1+ import { useSwaggerDocStore } from "@/entities/docs/model/store/document-store" ;
2+ import { useGETDocs } from "@/entities/swagger/api/get-document" ;
13import { Schemas } from "@/entities/swagger/types" ;
24import { FormValues } from "@/features/request-api/module/hooks/useForm" ;
35import { vars } from "@/shared/ui/styles/theme.css" ;
6+ import { typeConverter } from "@/shared/util/typeConverter" ;
47import React , { ChangeEvent , useState } from "react" ;
58import { RequestArrayBody } from "../array-body/RequestArrayBody" ;
69import { RequestNormalBody } from "../normal-body/RequestNormalBody" ;
@@ -26,6 +29,11 @@ export const RequestBody = ({
2629 // 기존에 custom hook으로 관리하던 paramState와 달리 하나의 input만 담당
2730 const [ bodyValue , setBodyValue ] = useState ( "" ) ;
2831
32+ const { pathInfo } = useSwaggerDocStore ( ) ;
33+
34+ const { data : apiDocsData } = useGETDocs ( pathInfo ) ;
35+ console . log ( apiDocsData ) ;
36+
2937 const onChangeBodyValue = ( e : ChangeEvent < HTMLInputElement > ) => {
3038 // file type일 경우 직접 addArrayItem 호출
3139 if ( e . target . id === "file" && e . target . files ) {
@@ -40,16 +48,29 @@ export const RequestBody = ({
4048 setBodyValue ( "" ) ;
4149 } ;
4250
43- const isItemsTypeFile = ( property : string ) => {
44- let returnType = "text" ;
51+ const isFileType = ( property : string ) => {
4552 Object . keys ( body . properties ) . map ( ( property ) => {
4653 if ( body . properties [ property ] ?. format === "binary" ) {
47- returnType = "file" ;
54+ return true ;
4855 }
4956 } ) ;
50- // if (body.properties[property].type === "binary") return "file";
51- if ( body . properties [ property ] . items ?. format === "binary" ) return "file" ;
52- return returnType ;
57+ if ( body . properties [ property ] . items ?. format === "binary" ) return true ;
58+ return false ;
59+ } ;
60+
61+ const getType = ( property : string ) => {
62+ const type = body . properties [ property ] . type ;
63+ if ( type ) {
64+ console . log ( "type" , type ) ;
65+ return typeConverter ( type ) ;
66+ }
67+ const fullRef = body . properties [ property ] . $ref ;
68+ console . log ( "fullRef" , fullRef ) ;
69+ const ref = fullRef . split ( "/" ) . pop ( ) ;
70+ console . log ( "ref" , ref ) ;
71+ const schema = apiDocsData ?. components ?. schemas [ ref ] ;
72+ console . log ( schema ) ;
73+ return typeConverter ( schema ?. type ) ;
5374 } ;
5475
5576 return (
@@ -71,7 +92,8 @@ export const RequestBody = ({
7192 property = { property }
7293 addArrayItem = { onAddArrayItem }
7394 removeArrayItem = { removeArrayItem }
74- type = { isItemsTypeFile ( property ) }
95+ type = { getType ( property ) }
96+ isFileType = { isFileType ( property ) }
7597 />
7698 ) : (
7799 < RequestNormalBody
@@ -80,7 +102,8 @@ export const RequestBody = ({
80102 handleChange = { handleChange }
81103 idx = { idx }
82104 property = { property }
83- type = { isItemsTypeFile ( property ) }
105+ type = { getType ( property ) }
106+ isFileType = { isFileType ( property ) }
84107 />
85108 ) }
86109 </ >
0 commit comments