diff --git a/src/openApi/v3/parser/getOperation.ts b/src/openApi/v3/parser/getOperation.ts index fadee93af..843a4e39f 100644 --- a/src/openApi/v3/parser/getOperation.ts +++ b/src/openApi/v3/parser/getOperation.ts @@ -78,16 +78,9 @@ export const getOperation = ( mediaType: null, }; - // Parse the operation parameters (path, query, body, etc). - if (op.parameters) { - const parameters = getOperationParameters(openApi, op.parameters); - - const queryParams = parameters.parameters.filter(p => p.in === 'query'); - if (queryParams.length !== 0) { - dataParameter.properties.push(...queryParams); - dataParameter.isRequired = !!queryParams.find(p => p.isRequired); - } - + // Parse the operation parameters (path, body, etc). Query parameters are not included here + const parameters = op.parameters ? getOperationParameters(openApi, op.parameters) : undefined; + if (parameters) { const newParams = parameters.parameters.filter(p => p.in !== 'query'); operation.imports.push(...parameters.imports); operation.parameters.push(...newParams); @@ -117,6 +110,15 @@ export const getOperation = ( dataParameter.isRequired = requestBody.isRequired ? true : dataParameter.isRequired; } + // Add query parameters after path and body parameters are processed. + if (parameters) { + const queryParams = parameters.parameters.filter(p => p.in === 'query'); + if (queryParams.length !== 0) { + dataParameter.properties.push(...queryParams); + dataParameter.isRequired = !!queryParams.find(p => p.isRequired); + } + } + // Parse the operation responses. if (op.responses) { const operationResponses = getOperationResponses(openApi, op.responses); diff --git a/test/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index aa0cdbf6b..876685551 100644 --- a/test/__snapshots__/index.spec.ts.snap +++ b/test/__snapshots__/index.spec.ts.snap @@ -5269,6 +5269,7 @@ export { MultipleTags1Service } from './services/MultipleTags1Service.js'; export { MultipleTags2Service } from './services/MultipleTags2Service.js'; export { MultipleTags3Service } from './services/MultipleTags3Service.js'; export { NoContentService } from './services/NoContentService.js'; +export { OneOfService } from './services/OneOfService.js'; export { ParametersService } from './services/ParametersService.js'; export { RequestBodyService } from './services/RequestBodyService.js'; export { ResponseService } from './services/ResponseService.js'; @@ -5297,6 +5298,7 @@ import { MultipleTags1Service } from './services/MultipleTags1Service.js'; import { MultipleTags2Service } from './services/MultipleTags2Service.js'; import { MultipleTags3Service } from './services/MultipleTags3Service.js'; import { NoContentService } from './services/NoContentService.js'; +import { OneOfService } from './services/OneOfService.js'; import { ParametersService } from './services/ParametersService.js'; import { RequestBodyService } from './services/RequestBodyService.js'; import { ResponseService } from './services/ResponseService.js'; @@ -5378,6 +5380,7 @@ applyMixins(LuneClient, [ MultipleTags2Service, MultipleTags3Service, NoContentService, + OneOfService, ParametersService, RequestBodyService, ResponseService, @@ -5402,6 +5405,7 @@ export interface LuneClient extends MultipleTags2Service, MultipleTags3Service, NoContentService, + OneOfService, ParametersService, RequestBodyService, ResponseService, @@ -5493,6 +5497,7 @@ export { MultipleTags1Service } from './services/MultipleTags1Service.js'; export { MultipleTags2Service } from './services/MultipleTags2Service.js'; export { MultipleTags3Service } from './services/MultipleTags3Service.js'; export { NoContentService } from './services/NoContentService.js'; +export { OneOfService } from './services/OneOfService.js'; export { ParametersService } from './services/ParametersService.js'; export { RequestBodyService } from './services/RequestBodyService.js'; export { ResponseService } from './services/ResponseService.js'; @@ -9727,14 +9732,14 @@ export abstract class FormDataService { */ public postApiFormData( data?: { - /** - * This is a reusable parameter - */ - parameter?: string; /** * This is a simple string property */ prop?: string; + /** + * This is a reusable parameter + */ + parameter?: string; }, options?: { /** @@ -10093,6 +10098,69 @@ export abstract class NoContentService { }" `; +exports[`v3 should generate: ./test/generated/v3/services/OneOfService.ts 1`] = ` +"// ========================================================================================= +// +// This file is AUTO-GENERATED by https://github.com/lune-climate/openapi-typescript-codegen +// +// In most cases you DON'T WANT TO MAKE MANUAL CHANGES to it – they WILL BE OVERWRITTEN. +// +// ========================================================================================= + +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ModelWithArray } from '../models/ModelWithArray.js'; +import type { ModelWithDictionary } from '../models/ModelWithDictionary.js'; +import type { ModelWithEnum } from '../models/ModelWithEnum.js'; +import type { ModelWithString } from '../models/ModelWithString.js'; + +import { ClientConfig } from '../core/ClientConfig.js' +import { request as __request } from '../core/request.js' +import { ApiError } from '../core/ApiError.js' +import { AxiosInstance } from 'axios' +import { Result } from 'ts-results-es' + +export abstract class OneOfService { + protected abstract client: AxiosInstance + protected abstract config: ClientConfig + + /** + * @param data Request data + * @param options Additional operation options + */ + public queryParamsWithOneOf( + data?: { + /** + * Testing allOf request body at the root level + */ + modelWithOneOfRoot: (ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary); + /** + * This is a reusable parameter + */ + parameter?: string; + }, + options?: { + /** + * Account Id to be used to perform the API call + */ + accountId?: string; + }, + ): Promise> { + return __request(this.client, this.config, options || {}, { + method: 'POST', + url: '/api/v{api-version}/queryParamsWithOneOf', + query: { + 'parameter': data?.parameter, + }, + body: data?.modelWithOneOfRoot, + mediaType: 'application/json', + }); + } + +}" +`; + exports[`v3 should generate: ./test/generated/v3/services/ParametersService.ts 1`] = ` "// ========================================================================================= // @@ -10191,14 +10259,14 @@ export abstract class ParametersService { * This is the parameter that goes into the request query params */ parameterQuery: string | null; - /** - * This is the parameter with a reserved keyword - */ - default?: string; /** * This is a simple string property */ prop?: string; + /** + * This is the parameter with a reserved keyword + */ + default?: string; }, parameterPath1?: string, parameterPath2?: string, @@ -10243,15 +10311,15 @@ export abstract class ParametersService { * @param options Additional operation options */ public getCallWithOptionalParam( - data: { - /** - * This is an optional parameter - */ - parameter?: string; + data?: { /** * This is a simple string property */ prop?: string; + /** + * This is an optional parameter + */ + parameter?: string; }, options?: { /** @@ -10339,14 +10407,14 @@ export abstract class RequestBodyService { */ public postApiRequestBody( data?: { - /** - * This is a reusable parameter - */ - parameter?: string; /** * This is a simple string property */ prop?: string; + /** + * This is a reusable parameter + */ + parameter?: string; }, options?: { /** diff --git a/test/spec/v3.json b/test/spec/v3.json index 60e7def2e..d150db9a8 100644 --- a/test/spec/v3.json +++ b/test/spec/v3.json @@ -1478,6 +1478,29 @@ } } } + }, + "/api/v{api-version}/queryParamsWithOneOf": { + "post": { + "tags": ["OneOf"], + "parameters": [ + { + "$ref": "#/components/parameters/SimpleParameter" + } + ], + "operationId": "QueryParamsWithOneOf", + "requestBody": { + "description": "Testing allOf request body at the root level", + "required": true, + "nullable": false, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ModelWithOneOfRoot" + } + } + } + } + } } }, "components": {