MCPcopy Create free account
hub / github.com/middleapi/orpc / toOpenAPIParameters

Function toOpenAPIParameters

packages/openapi/src/openapi-utils.ts:103–138  ·  view source on GitHub ↗
(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie')

Source from the content-addressed store, hash-verified

101 * @internal
102 */
103export function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[] {
104 const parameters: OpenAPI.ParameterObject[] = []
105
106 for (const key in schema.properties) {
107 const keySchema = schema.properties[key]!
108
109 let isDeepObjectStyle = true
110
111 if (parameterIn !== 'query') {
112 isDeepObjectStyle = false
113 }
114 else if (isPrimitiveSchema(keySchema)) {
115 isDeepObjectStyle = false
116 }
117 else {
118 const [item] = expandArrayableSchema(keySchema) ?? []
119
120 if (item !== undefined && isPrimitiveSchema(item)) {
121 isDeepObjectStyle = false
122 }
123 }
124
125 parameters.push({
126 name: key,
127 in: parameterIn,
128 required: schema.required?.includes(key),
129 schema: toOpenAPISchema(keySchema) as any,
130 style: isDeepObjectStyle ? 'deepObject' : undefined,
131 explode: isDeepObjectStyle ? true : undefined,
132 allowEmptyValue: parameterIn === 'query' ? true : undefined,
133 allowReserved: parameterIn === 'query' ? true : undefined,
134 })
135 }
136
137 return parameters
138}
139
140/**
141 * @internal

Callers 2

#requestMethod · 0.90

Calls 4

isPrimitiveSchemaFunction · 0.90
expandArrayableSchemaFunction · 0.90
toOpenAPISchemaFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected