MCPcopy Create free account
hub / github.com/middleapi/orpc / #request

Method #request

packages/openapi/src/openapi-generator.ts:278–415  ·  view source on GitHub ↗
(
    doc: OpenAPI.Document,
    ref: OpenAPI.OperationObject,
    def: AnyContractProcedure['~orpc'],
    baseSchemaConvertOptions: Pick<SchemaConvertOptions, 'components'>,
  )

Source from the content-addressed store, hash-verified

276 }
277
278 async #request(
279 doc: OpenAPI.Document,
280 ref: OpenAPI.OperationObject,
281 def: AnyContractProcedure['~orpc'],
282 baseSchemaConvertOptions: Pick<SchemaConvertOptions, 'components'>,
283 ): Promise<void> {
284 const method = fallbackContractConfig('defaultMethod', def.route.method)
285 const details = getEventIteratorSchemaDetails(def.inputSchema)
286
287 if (details) {
288 ref.requestBody = {
289 required: true,
290 content: toOpenAPIEventIteratorContent(
291 await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: 'input' }),
292 await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: 'input' }),
293 ),
294 }
295
296 return
297 }
298
299 const dynamicParams = getDynamicParams(def.route.path)?.map(v => v.name)
300 const inputStructure = fallbackContractConfig('defaultInputStructure', def.route.inputStructure)
301
302 let [required, schema] = await this.converter.convert(
303 def.inputSchema,
304 {
305 ...baseSchemaConvertOptions,
306 strategy: 'input',
307 },
308 )
309
310 let omitResponseBody = false
311
312 if (isAnySchema(schema) && !dynamicParams?.length) {
313 return
314 }
315
316 if (inputStructure === 'detailed' || (inputStructure === 'compact' && (dynamicParams?.length || method === 'GET'))) {
317 schema = simplifyComposedObjectJsonSchemasAndRefs(schema, doc)
318 }
319
320 if (inputStructure === 'compact') {
321 if (dynamicParams?.length) {
322 const error = new OpenAPIGeneratorError(
323 'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.',
324 )
325
326 if (!isObjectSchema(schema)) {
327 throw error
328 }
329
330 const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams)
331
332 schema = rest
333 required = rest.required ? rest.required.length !== 0 : false
334 omitResponseBody = !required && !rest.properties
335

Callers 1

generateMethod · 0.95

Calls 13

fallbackContractConfigFunction · 0.90
getDynamicParamsFunction · 0.90
isAnySchemaFunction · 0.90
isObjectSchemaFunction · 0.90
separateObjectSchemaFunction · 0.90
checkParamsSchemaFunction · 0.90
toOpenAPIParametersFunction · 0.90
toOpenAPIContentFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected