@@ -143,39 +143,6 @@ export async function generateOpenAPI(opts: GenerateOpenAPIOpts) {
143143 file_path ,
144144 { setupParams, routeSpec, route : routePath } ,
145145 ] of filepathToRouteFn ) {
146- const isPostOrPutOrPatch = [ "POST" , "PUT" , "PATCH" ] . some ( ( method ) =>
147- routeSpec . methods . includes ( method )
148- )
149- // TODO: support multipart/form-data
150-
151- // handle body
152- let body_to_generate_schema
153- if ( isPostOrPutOrPatch ) {
154- body_to_generate_schema = routeSpec . jsonBody ?? routeSpec . commonParams
155-
156- if ( routeSpec . jsonBody && routeSpec . commonParams ) {
157- body_to_generate_schema = routeSpec . jsonBody . merge (
158- routeSpec . commonParams
159- )
160- }
161- } else {
162- body_to_generate_schema = routeSpec . jsonBody
163- }
164-
165- // handle query
166- let query_to_generate_schema
167- if ( isPostOrPutOrPatch ) {
168- query_to_generate_schema = routeSpec . queryParams
169- } else {
170- query_to_generate_schema = routeSpec . queryParams ?? routeSpec . commonParams
171-
172- if ( routeSpec . queryParams && routeSpec . commonParams ) {
173- query_to_generate_schema = routeSpec . queryParams . merge (
174- routeSpec . commonParams
175- )
176- }
177- }
178-
179146 const methods = routeSpec . methods
180147 if ( methods . length === 0 ) {
181148 console . warn (
@@ -206,14 +173,12 @@ export async function generateOpenAPI(opts: GenerateOpenAPIOpts) {
206173 dashifyObjectKeys ( descriptionMetadata )
207174 )
208175
209- // Create a map to store method-specific route objects
210176 const methodRoutes : Record < string , OperationObject > = { }
211177
212- // Loop through each method and create method-specific route objects
213178 for ( const method of methods ) {
214179 const isPostOrPutOrPatch = [ "POST" , "PUT" , "PATCH" ] . includes ( method )
215180
216- // Calculate body schema for this specific method
181+ // TODO: support multipart/form-data
217182 let body_to_generate_schema
218183 if ( isPostOrPutOrPatch ) {
219184 body_to_generate_schema = routeSpec . jsonBody ?? routeSpec . commonParams
@@ -227,7 +192,6 @@ export async function generateOpenAPI(opts: GenerateOpenAPIOpts) {
227192 body_to_generate_schema = routeSpec . jsonBody
228193 }
229194
230- // Calculate query schema for this specific method
231195 let query_to_generate_schema
232196 if ( isPostOrPutOrPatch ) {
233197 query_to_generate_schema = routeSpec . queryParams
@@ -242,7 +206,6 @@ export async function generateOpenAPI(opts: GenerateOpenAPIOpts) {
242206 }
243207 }
244208
245- // Create base route object for this method
246209 const route : OperationObject = {
247210 ...routeSpec . openApiMetadata ,
248211 ...formattedDescriptionMetadata ,
@@ -269,7 +232,6 @@ export async function generateOpenAPI(opts: GenerateOpenAPIOpts) {
269232 : securityObjectsForAuthType [ routeSpec . auth ] ,
270233 }
271234
272- // Add request body if applicable for this method
273235 if ( body_to_generate_schema ) {
274236 route . requestBody = {
275237 content : {
@@ -280,7 +242,6 @@ export async function generateOpenAPI(opts: GenerateOpenAPIOpts) {
280242 }
281243 }
282244
283- // Add parameters if applicable for this method
284245 if ( query_to_generate_schema ) {
285246 const schema = generateSchema ( query_to_generate_schema as any )
286247 if ( schema . properties ) {
@@ -299,7 +260,6 @@ export async function generateOpenAPI(opts: GenerateOpenAPIOpts) {
299260 }
300261 }
301262
302- // Handle JSON response
303263 const { jsonResponse } = routeSpec
304264 const { addOkStatus = true } = setupParams
305265
@@ -329,6 +289,7 @@ export async function generateOpenAPI(opts: GenerateOpenAPIOpts) {
329289 )
330290
331291 if ( route . responses != null ) {
292+ // TODO: we should not hardcode 200 here
332293 route . responses [ 200 ] . content = {
333294 "application/json" : {
334295 schema : schemaWithReferences ,
@@ -337,29 +298,24 @@ export async function generateOpenAPI(opts: GenerateOpenAPIOpts) {
337298 }
338299 }
339300
340- // Add tags
341301 route . tags = [ ]
342302 for ( const tag of tags ) {
343303 if ( tag . doesRouteHaveTag && tag . doesRouteHaveTag ( route . summary || "" ) ) {
344304 route . tags . push ( tag . name )
345305 }
346306 }
347307
348- // Get Fern SDK metadata for this specific method
349308 const methodsMappedToFernSdkMetadata = await mapMethodsToFernSdkMetadata ( {
350309 methods : [ method ] , // Only pass this specific method
351310 path : routePath ,
352311 sdkReturnValue :
353312 descriptionMetadata ?. response_key ?? routeSpec . sdkReturnValue ,
354313 } )
355314
356- // Apply method-specific metadata
357315 Object . assign ( route , methodsMappedToFernSdkMetadata [ method ] )
358-
359- // Store the route for this method
360316 methodRoutes [ method . toLowerCase ( ) ] = route
361317 }
362- // Some routes accept multiple methods
318+
363319 builder . addPath ( routePath , methodRoutes )
364320 }
365321
0 commit comments