mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
Merge branch 'master' into feature/test
# Conflicts: # src/openApi/v3/parser/getOperationResponse.ts
This commit is contained in:
commit
1b82dee276
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "openapi-typescript-codegen",
|
||||
"version": "0.11.1",
|
||||
"version": "0.11.2",
|
||||
"description": "Library that generates Typescript clients based on the OpenAPI specification.",
|
||||
"author": "Ferdi Koomen",
|
||||
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",
|
||||
|
||||
@ -2,6 +2,7 @@ import type { OperationParameter } from '../../../client/interfaces/OperationPar
|
||||
import { getPattern } from '../../../utils/getPattern';
|
||||
import type { OpenApi } from '../interfaces/OpenApi';
|
||||
import type { OpenApiParameter } from '../interfaces/OpenApiParameter';
|
||||
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
|
||||
import { extendEnum } from './extendEnum';
|
||||
import { getComment } from './getComment';
|
||||
import { getEnum } from './getEnum';
|
||||
@ -9,6 +10,7 @@ import { getEnumFromDescription } from './getEnumFromDescription';
|
||||
import { getModel } from './getModel';
|
||||
import { getOperationParameterDefault } from './getOperationParameterDefault';
|
||||
import { getOperationParameterName } from './getOperationParameterName';
|
||||
import { getRef } from './getRef';
|
||||
import { getType } from './getType';
|
||||
|
||||
export function getOperationParameter(openApi: OpenApi, parameter: OpenApiParameter): OperationParameter {
|
||||
@ -103,9 +105,13 @@ export function getOperationParameter(openApi: OpenApi, parameter: OpenApiParame
|
||||
return operationParameter;
|
||||
}
|
||||
|
||||
if (parameter.schema) {
|
||||
if (parameter.schema.$ref) {
|
||||
const model = getType(parameter.schema.$ref);
|
||||
let schema = parameter.schema;
|
||||
if (schema) {
|
||||
if (schema.$ref?.startsWith('#/parameters/')) {
|
||||
schema = getRef<OpenApiSchema>(openApi, schema);
|
||||
}
|
||||
if (schema.$ref) {
|
||||
const model = getType(schema.$ref);
|
||||
operationParameter.export = 'reference';
|
||||
operationParameter.type = model.type;
|
||||
operationParameter.base = model.base;
|
||||
@ -114,7 +120,7 @@ export function getOperationParameter(openApi: OpenApi, parameter: OpenApiParame
|
||||
operationParameter.default = getOperationParameterDefault(parameter, operationParameter);
|
||||
return operationParameter;
|
||||
} else {
|
||||
const model = getModel(openApi, parameter.schema);
|
||||
const model = getModel(openApi, schema);
|
||||
operationParameter.export = model.export;
|
||||
operationParameter.type = model.type;
|
||||
operationParameter.base = model.base;
|
||||
|
||||
@ -2,8 +2,10 @@ import type { OperationResponse } from '../../../client/interfaces/OperationResp
|
||||
import { getPattern } from '../../../utils/getPattern';
|
||||
import type { OpenApi } from '../interfaces/OpenApi';
|
||||
import type { OpenApiResponse } from '../interfaces/OpenApiResponse';
|
||||
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
|
||||
import { getComment } from './getComment';
|
||||
import { getModel } from './getModel';
|
||||
import { getRef } from './getRef';
|
||||
import { getType } from './getType';
|
||||
|
||||
export function getOperationResponse(
|
||||
@ -35,9 +37,13 @@ export function getOperationResponse(
|
||||
// if this is a reference then the parameter is just the 'name' of
|
||||
// this reference type. Otherwise it might be a complex schema and
|
||||
// then we need to parse the schema!
|
||||
if (response.schema) {
|
||||
if (response.schema.$ref) {
|
||||
const model = getType(response.schema.$ref);
|
||||
let schema = response.schema;
|
||||
if (schema) {
|
||||
if (schema.$ref?.startsWith('#/responses/')) {
|
||||
schema = getRef<OpenApiSchema>(openApi, schema);
|
||||
}
|
||||
if (schema.$ref) {
|
||||
const model = getType(schema.$ref);
|
||||
operationResponse.export = 'reference';
|
||||
operationResponse.type = model.type;
|
||||
operationResponse.base = model.base;
|
||||
@ -45,7 +51,7 @@ export function getOperationResponse(
|
||||
operationResponse.imports.push(...model.imports);
|
||||
return operationResponse;
|
||||
} else {
|
||||
const model = getModel(openApi, response.schema);
|
||||
const model = getModel(openApi, schema);
|
||||
operationResponse.export = model.export;
|
||||
operationResponse.type = model.type;
|
||||
operationResponse.base = model.base;
|
||||
|
||||
@ -2,10 +2,12 @@ import type { OperationParameter } from '../../../client/interfaces/OperationPar
|
||||
import { getPattern } from '../../../utils/getPattern';
|
||||
import type { OpenApi } from '../interfaces/OpenApi';
|
||||
import type { OpenApiParameter } from '../interfaces/OpenApiParameter';
|
||||
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
|
||||
import { getComment } from './getComment';
|
||||
import { getModel } from './getModel';
|
||||
import { getModelDefault } from './getModelDefault';
|
||||
import { getOperationParameterName } from './getOperationParameterName';
|
||||
import { getRef } from './getRef';
|
||||
import { getType } from './getType';
|
||||
|
||||
export function getOperationParameter(openApi: OpenApi, parameter: OpenApiParameter): OperationParameter {
|
||||
@ -40,18 +42,22 @@ export function getOperationParameter(openApi: OpenApi, parameter: OpenApiParame
|
||||
return operationParameter;
|
||||
}
|
||||
|
||||
if (parameter.schema) {
|
||||
if (parameter.schema.$ref) {
|
||||
const model = getType(parameter.schema.$ref);
|
||||
let schema = parameter.schema;
|
||||
if (schema) {
|
||||
if (schema.$ref?.startsWith('#/components/parameters/')) {
|
||||
schema = getRef<OpenApiSchema>(openApi, schema);
|
||||
}
|
||||
if (schema.$ref) {
|
||||
const model = getType(schema.$ref);
|
||||
operationParameter.export = 'reference';
|
||||
operationParameter.type = model.type;
|
||||
operationParameter.base = model.base;
|
||||
operationParameter.template = model.template;
|
||||
operationParameter.imports.push(...model.imports);
|
||||
operationParameter.default = getModelDefault(parameter.schema);
|
||||
operationParameter.default = getModelDefault(schema);
|
||||
return operationParameter;
|
||||
} else {
|
||||
const model = getModel(openApi, parameter.schema);
|
||||
const model = getModel(openApi, schema);
|
||||
operationParameter.export = model.export;
|
||||
operationParameter.type = model.type;
|
||||
operationParameter.base = model.base;
|
||||
|
||||
@ -2,9 +2,11 @@ import type { OperationResponse } from '../../../client/interfaces/OperationResp
|
||||
import { getPattern } from '../../../utils/getPattern';
|
||||
import type { OpenApi } from '../interfaces/OpenApi';
|
||||
import type { OpenApiResponse } from '../interfaces/OpenApiResponse';
|
||||
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
|
||||
import { getComment } from './getComment';
|
||||
import { getContent } from './getContent';
|
||||
import { getModel } from './getModel';
|
||||
import { getRef } from './getRef';
|
||||
import { getType } from './getType';
|
||||
|
||||
export function getOperationResponse(
|
||||
@ -35,6 +37,9 @@ export function getOperationResponse(
|
||||
if (response.content) {
|
||||
const content = getContent(openApi, response.content);
|
||||
if (content) {
|
||||
if (content.schema.$ref?.startsWith('#/components/responses/')) {
|
||||
content.schema = getRef<OpenApiSchema>(openApi, content.schema);
|
||||
}
|
||||
if (content.schema.$ref) {
|
||||
const model = getType(content.schema.$ref);
|
||||
operationResponse.export = 'reference';
|
||||
|
||||
@ -1363,6 +1363,11 @@
|
||||
jest-diff "^27.0.0"
|
||||
pretty-format "^27.0.0"
|
||||
|
||||
"@types/js-yaml@4.0.4":
|
||||
version "4.0.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.4.tgz#cc38781257612581a1a0eb25f1709d2b06812fce"
|
||||
integrity sha512-AuHubXUmg0AzkXH0Mx6sIxeY/1C110mm/EkE/gB1sTRz3h2dao2W/63q42SlVST+lICxz5Oki2hzYA6+KnnieQ==
|
||||
|
||||
"@types/json-schema@^7.0.6", "@types/json-schema@^7.0.9":
|
||||
version "7.0.9"
|
||||
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
|
||||
@ -3534,7 +3539,7 @@ js-yaml@3.14.1, js-yaml@^3.13.1:
|
||||
argparse "^1.0.7"
|
||||
esprima "^4.0.0"
|
||||
|
||||
js-yaml@^4.1.0:
|
||||
js-yaml@4.1.0, js-yaml@^4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
|
||||
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user