diff --git a/src/entities/swagger/types/index.ts b/src/entities/swagger/types/index.ts index ce80642..247b783 100644 --- a/src/entities/swagger/types/index.ts +++ b/src/entities/swagger/types/index.ts @@ -49,6 +49,7 @@ export interface SchemasProperties { type: SwaggerType; format?: SwaggerFormat; }; + $ref?: string; } export interface Schemas { diff --git a/src/shared/util/typeConverter.ts b/src/shared/util/typeConverter.ts index f4ee50d..9fe4f45 100644 --- a/src/shared/util/typeConverter.ts +++ b/src/shared/util/typeConverter.ts @@ -1,5 +1,6 @@ const typeConverter = (type: string) => { if (type === "integer") return "number"; + if (!type) return "unknown"; return type; }; diff --git a/src/widgets/request-body/ui/api-body/RequestBody.tsx b/src/widgets/request-body/ui/api-body/RequestBody.tsx index 0e7178a..e7b2e38 100644 --- a/src/widgets/request-body/ui/api-body/RequestBody.tsx +++ b/src/widgets/request-body/ui/api-body/RequestBody.tsx @@ -1,6 +1,9 @@ +import { useSwaggerDocStore } from "@/entities/docs/model/store/document-store"; +import { useGETDocs } from "@/entities/swagger/api/get-document"; import { Schemas } from "@/entities/swagger/types"; import { FormValues } from "@/features/request-api/module/hooks/useForm"; import { vars } from "@/shared/ui/styles/theme.css"; +import { typeConverter } from "@/shared/util/typeConverter"; import React, { ChangeEvent, useState } from "react"; import { RequestArrayBody } from "../array-body/RequestArrayBody"; import { RequestNormalBody } from "../normal-body/RequestNormalBody"; @@ -26,6 +29,11 @@ export const RequestBody = ({ // 기존에 custom hook으로 관리하던 paramState와 달리 하나의 input만 담당 const [bodyValue, setBodyValue] = useState(""); + const { pathInfo } = useSwaggerDocStore(); + + const { data: apiDocsData } = useGETDocs(pathInfo); + console.log(apiDocsData); + const onChangeBodyValue = (e: ChangeEvent) => { // file type일 경우 직접 addArrayItem 호출 if (e.target.id === "file" && e.target.files) { @@ -40,16 +48,29 @@ export const RequestBody = ({ setBodyValue(""); }; - const isItemsTypeFile = (property: string) => { - let returnType = "text"; + const isFileType = (property: string) => { Object.keys(body.properties).map((property) => { if (body.properties[property]?.format === "binary") { - returnType = "file"; + return true; } }); - // if (body.properties[property].type === "binary") return "file"; - if (body.properties[property].items?.format === "binary") return "file"; - return returnType; + if (body.properties[property].items?.format === "binary") return true; + return false; + }; + + const getType = (property: string) => { + const type = body.properties[property].type; + if (type) { + console.log("type", type); + return typeConverter(type); + } + const fullRef = body.properties[property].$ref; + console.log("fullRef", fullRef); + const ref = fullRef.split("/").pop(); + console.log("ref", ref); + const schema = apiDocsData?.components?.schemas[ref]; + console.log(schema); + return typeConverter(schema?.type); }; return ( @@ -71,7 +92,8 @@ export const RequestBody = ({ property={property} addArrayItem={onAddArrayItem} removeArrayItem={removeArrayItem} - type={isItemsTypeFile(property)} + type={getType(property)} + isFileType={isFileType(property)} /> ) : ( )} diff --git a/src/widgets/request-body/ui/array-body/RequestArrayBody.tsx b/src/widgets/request-body/ui/array-body/RequestArrayBody.tsx index b8fe131..7050477 100644 --- a/src/widgets/request-body/ui/array-body/RequestArrayBody.tsx +++ b/src/widgets/request-body/ui/array-body/RequestArrayBody.tsx @@ -10,6 +10,7 @@ interface RequestArrayBodyProps { formValues: FormValues; idx: number; property: string; + isFileType: boolean; type: string; handleChange: (e: ChangeEvent) => void; addArrayItem: (key: string) => void; @@ -22,6 +23,7 @@ export const RequestArrayBody = ({ idx, property, type, + isFileType, addArrayItem, removeArrayItem, handleChange, @@ -35,7 +37,7 @@ export const RequestArrayBody = ({ {typeConverter(body.properties[property].type)}
- {type === "file" && ( + {!!isFileType && (