11import type { Input } from "../../core/input"
22import { logger } from "../../core/logger"
3- import type { IROperation } from "../../core/openapi-types-normalized"
3+ import type { IRModel , IROperation } from "../../core/openapi-types-normalized"
44import { extractPlaceholders } from "../../core/openapi-utils"
55import type { SchemaBuilder } from "../common/schema-builders/schema-builder"
66import type { TypeBuilder } from "../common/type-builder"
@@ -33,6 +33,23 @@ export type ServerOperationResponseSchemas = {
3333 | undefined
3434}
3535
36+ export type PrimitiveType = { type : "string" | "number" | "boolean" | "null" }
37+ export type ObjectSchema = {
38+ type : "object"
39+ properties : Record < string , SchemaStructure >
40+ }
41+ export type ArraySchema = { type : "array" ; items : SchemaStructure }
42+
43+ export type SchemaStructure = PrimitiveType | ObjectSchema | ArraySchema
44+ export type Style = "deepObject" | "form" | "pipeDelimited" | "spaceDelimited"
45+ export interface QueryParameter {
46+ name : string
47+ schema : SchemaStructure
48+ style ?: Style
49+ explode ?: boolean
50+ // allowEmptyValue: boolean
51+ }
52+
3653export type Parameters = {
3754 type : string
3855 path : {
@@ -44,6 +61,7 @@ export type Parameters = {
4461 name : string
4562 schema : string | undefined
4663 type : string
64+ parameters : QueryParameter [ ]
4765 }
4866 header : {
4967 name : string
@@ -191,7 +209,54 @@ export class ServerOperationBuilder {
191209 type = this . types . schemaObjectToType ( $ref )
192210 }
193211
194- return { name : this . operation . parameters . query . name , schema : schema , type}
212+
213+ return {
214+ name : this . operation . parameters . query . name ,
215+ schema : schema ,
216+ type,
217+ parameters : this . operation . parameters . query . list . map ( ( it ) => ( {
218+ name : it . name ,
219+ // todo: only default true when style: form
220+ // todo: remove defaulting - normalization does this
221+ explode : it . explode ?? true ,
222+ style : it . style ?? "form" ,
223+ schema : this . queryParameterRuntimeSchema ( this . input . schema ( it . schema ) ) ,
224+ } ) ) ,
225+ }
226+ }
227+
228+ private queryParameterRuntimeSchema ( schema : IRModel ) : SchemaStructure {
229+ const type = schema . type
230+ switch ( type ) {
231+ case "string" :
232+ case "number" :
233+ case "boolean" :
234+ return { type}
235+ case "array" :
236+ return {
237+ type : "array" ,
238+ items : this . queryParameterRuntimeSchema (
239+ this . input . schema ( schema . items ) ,
240+ ) ,
241+ }
242+ case "object" : {
243+ const properties : Record < string , SchemaStructure > = { }
244+
245+ for ( const key in schema . properties ) {
246+ properties [ key ] = this . queryParameterRuntimeSchema (
247+ this . input . schema ( schema . properties [ key ] ?? { isIRModel : true , nullable : false , readOnly : false , type : "any" } ) ,
248+ )
249+ }
250+
251+ return {
252+ type : "object" ,
253+ properties,
254+ }
255+ }
256+ default : {
257+ throw new Error ( `unsupported query parameter type ${ type } ` )
258+ }
259+ }
195260 }
196261
197262 private headerParameters ( ) : Parameters [ "header" ] {
0 commit comments