Skip to content

Commit 7b9ed36

Browse files
committed
chore: add OpenAPI 3.0.x interface
1 parent 2d52fd0 commit 7b9ed36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+4999
-105
lines changed

Diff for: .nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.10.0
1+
22.11.0

Diff for: packages/openapi-ts/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,6 @@ export default {
439439
defineConfig,
440440
};
441441

442-
export type { OpenApiV3_0_0 } from './openApi/3.0.x';
443-
export type { OpenApiV3_1_0 } from './openApi/3.1.x';
442+
export type { OpenApiV3_0_X } from './openApi/3.0.x';
443+
export type { OpenApiV3_1_X } from './openApi/3.1.x';
444444
export type { UserConfig } from './types/config';

Diff for: packages/openapi-ts/src/openApi/3.0.x/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { parseV3_0_0 } from './parser';
2-
export type { OpenApiV3_0_0 } from './types/spec';
1+
export { parseV3_0_X } from './parser';
2+
export type { OpenApiV3_0_X } from './types/spec';
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { IRContext } from '../../../ir/context';
2-
import type { OpenApiV3_0_0 } from '../types/spec';
2+
import type { OpenApiV3_0_X } from '../types/spec';
33

4-
export const parseV3_0_0 = (context: IRContext<OpenApiV3_0_0>) => {
4+
export const parseV3_0_X = (context: IRContext<OpenApiV3_0_X>) => {
55
// TODO
66
console.log(context.spec);
77
};

Diff for: packages/openapi-ts/src/openApi/3.0.x/types/spec.d.ts

+1,270-6
Large diffs are not rendered by default.

Diff for: packages/openapi-ts/src/openApi/3.1.x/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { parseV3_1_0 } from './parser';
2-
export type { OpenApiV3_1_0 } from './types/spec';
1+
export { parseV3_1_X } from './parser';
2+
export type { OpenApiV3_1_X } from './types/spec';

Diff for: packages/openapi-ts/src/openApi/3.1.x/parser/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { IRContext } from '../../../ir/context';
22
import type {
3-
OpenApiV3_1_0,
3+
OpenApiV3_1_X,
44
ParameterObject,
55
PathItemObject,
66
PathsObject,
@@ -13,7 +13,7 @@ import {
1313
} from './parameter';
1414
import { parseSchema } from './schema';
1515

16-
export const parseV3_1_0 = (context: IRContext<OpenApiV3_1_0>) => {
16+
export const parseV3_1_X = (context: IRContext<OpenApiV3_1_X>) => {
1717
const operationIds = new Map<string, string>();
1818

1919
for (const path in context.spec.paths) {

Diff for: packages/openapi-ts/src/openApi/3.1.x/types/json-schema-draft-2020-12.d.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import type {
2-
EnumExtensions,
3-
OpenApiSchemaExtensions,
4-
} from './spec-extensions';
1+
import type { EnumExtensions } from '../../common/types/openapi-spec-extensions';
2+
import type { OpenApiSchemaExtensions } from './spec-extensions';
53

64
// TODO: left out some keywords related to structuring a complex schema and declaring a dialect
75
export interface JsonSchemaDraft2020_12

Diff for: packages/openapi-ts/src/openApi/3.1.x/types/spec-extensions.d.ts

-15
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,6 @@ import type {
44
XMLObject,
55
} from './spec';
66

7-
export interface EnumExtensions {
8-
/**
9-
* `x-enum-descriptions` are {@link https://stackoverflow.com/a/66471626 supported} by OpenAPI Generator.
10-
*/
11-
'x-enum-descriptions'?: ReadonlyArray<string>;
12-
/**
13-
* `x-enum-varnames` are {@link https://stackoverflow.com/a/66471626 supported} by OpenAPI Generator.
14-
*/
15-
'x-enum-varnames'?: ReadonlyArray<string>;
16-
/**
17-
* {@link https://github.com/RicoSuter/NSwag NSwag} generates `x-enumNames` field containing custom enum names.
18-
*/
19-
'x-enumNames'?: ReadonlyArray<string>;
20-
}
21-
227
export interface OpenApiSchemaExtensions {
238
/**
249
* Adds support for polymorphism. The discriminator is an object name that is used to differentiate between other schemas which may satisfy the payload description. See {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#composition-and-inheritance-polymorphism Composition and Inheritance} for more details.

Diff for: packages/openapi-ts/src/openApi/3.1.x/types/spec.d.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { JsonSchemaDraft2020_12 } from './json-schema-draft-2020-12';
55
*
66
* This object MAY be extended with {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions Specification Extensions}.
77
*/
8-
export interface OpenApiV3_1_0 {
8+
export interface OpenApiV3_1_X {
99
/**
1010
* An element to hold various schemas for the document.
1111
*/
@@ -493,7 +493,14 @@ export interface EncodingObject {
493493
/**
494494
* Describes how a specific property value will be serialized depending on its type. See {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object Parameter Object} for details on the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterStyle `style`} property. The behavior follows the same values as `query` parameters, including default values. This property SHALL be ignored if the request body media type is not `application/x-www-form-urlencoded` or `multipart/form-data`. If a value is explicitly defined, then the value of {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#encodingContentType `contentType`} (implicit or explicit) SHALL be ignored.
495495
*/
496-
style?: string;
496+
style?:
497+
| 'deepObject'
498+
| 'form'
499+
| 'label'
500+
| 'matrix'
501+
| 'pipeDelimited'
502+
| 'simple'
503+
| 'spaceDelimited';
497504
}
498505

499506
/**
@@ -1622,7 +1629,7 @@ export interface ResponsesObject {
16221629
/**
16231630
* Any {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#http-status-codes HTTP status code} can be used as the property name, but only one property per code, to describe the expected response for that HTTP status code. This field MUST be enclosed in quotation marks (for example, "200") for compatibility between JSON and YAML. To define a range of response codes, this field MAY contain the uppercase wildcard character `X`. For example, `2XX` represents all response codes between `[200-299]`. Only the following range definitions are allowed: `1XX`, `2XX`, `3XX`, `4XX`, and `5XX`. If a response is defined using an explicit code, the explicit code definition takes precedence over the range definition for that code.
16241631
*/
1625-
[statusCode: string]: ResponseObject | ReferenceObject | undefined;
1632+
[httpStatusCode: string]: ResponseObject | ReferenceObject | undefined;
16261633
/**
16271634
* The documentation of responses other than the ones declared for specific HTTP response codes. Use this field to cover undeclared responses.
16281635
*/

Diff for: packages/openapi-ts/src/openApi/__tests__/index.spec.ts

+45-40
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { afterEach, describe, expect, it, vi } from 'vitest';
22

33
import { type OpenApi, parseExperimental, parseLegacy } from '..';
4-
import type { OpenApiV3_0_0 } from '../3.0.x';
5-
import { parseV3_0_0 } from '../3.0.x';
6-
import type { OpenApiV3_1_0 } from '../3.1.x';
7-
import { parseV3_1_0 } from '../3.1.x';
4+
import type { OpenApiV3_0_X } from '../3.0.x';
5+
import { parseV3_0_X } from '../3.0.x';
6+
import type { OpenApiV3_1_X } from '../3.1.x';
7+
import { parseV3_1_X } from '../3.1.x';
88
import type { ParserConfig } from '../config';
99
import * as parseV2 from '../v2';
1010
import * as parseV3 from '../v3';
1111

1212
vi.mock('../3.0.x', () => ({
13-
parseV3_0_0: vi.fn(),
13+
parseV3_0_X: vi.fn(),
1414
}));
1515
vi.mock('../3.1.x', () => ({
16-
parseV3_1_0: vi.fn(),
16+
parseV3_1_X: vi.fn(),
1717
}));
1818

1919
const parserConfig: ParserConfig = {
@@ -111,92 +111,97 @@ describe('experimentalParser', () => {
111111
});
112112

113113
it('handles OpenAPI 3.0.0', () => {
114-
const spec: OpenApiV3_0_0 = {
115-
// info: {
116-
// title: '',
117-
// version: '1',
118-
// },
114+
const spec: OpenApiV3_0_X = {
115+
info: {
116+
title: '',
117+
version: '1',
118+
},
119119
openapi: '3.0.0',
120+
paths: {},
120121
};
121122
parseExperimental({
122123
// @ts-ignore
123124
config: {},
124125
parserConfig,
125126
spec,
126127
});
127-
expect(parseV3_0_0).toHaveBeenCalled();
128+
expect(parseV3_0_X).toHaveBeenCalled();
128129
});
129130

130131
it('handles OpenAPI 3.0.1', () => {
131-
const spec: OpenApiV3_0_0 = {
132-
// info: {
133-
// title: '',
134-
// version: '1',
135-
// },
132+
const spec: OpenApiV3_0_X = {
133+
info: {
134+
title: '',
135+
version: '1',
136+
},
136137
openapi: '3.0.1',
138+
paths: {},
137139
};
138140
parseExperimental({
139141
// @ts-ignore
140142
config: {},
141143
parserConfig,
142144
spec,
143145
});
144-
expect(parseV3_0_0).toHaveBeenCalled();
146+
expect(parseV3_0_X).toHaveBeenCalled();
145147
});
146148

147149
it('handles OpenAPI 3.0.2', () => {
148-
const spec: OpenApiV3_0_0 = {
149-
// info: {
150-
// title: '',
151-
// version: '1',
152-
// },
150+
const spec: OpenApiV3_0_X = {
151+
info: {
152+
title: '',
153+
version: '1',
154+
},
153155
openapi: '3.0.2',
156+
paths: {},
154157
};
155158
parseExperimental({
156159
// @ts-ignore
157160
config: {},
158161
parserConfig,
159162
spec,
160163
});
161-
expect(parseV3_0_0).toHaveBeenCalled();
164+
expect(parseV3_0_X).toHaveBeenCalled();
162165
});
163166

164167
it('handles OpenAPI 3.0.3', () => {
165-
const spec: OpenApiV3_0_0 = {
166-
// info: {
167-
// title: '',
168-
// version: '1',
169-
// },
168+
const spec: OpenApiV3_0_X = {
169+
info: {
170+
title: '',
171+
version: '1',
172+
},
170173
openapi: '3.0.3',
174+
paths: {},
171175
};
172176
parseExperimental({
173177
// @ts-ignore
174178
config: {},
175179
parserConfig,
176180
spec,
177181
});
178-
expect(parseV3_0_0).toHaveBeenCalled();
182+
expect(parseV3_0_X).toHaveBeenCalled();
179183
});
180184

181185
it('handles OpenAPI 3.0.4', () => {
182-
const spec: OpenApiV3_0_0 = {
183-
// info: {
184-
// title: '',
185-
// version: '1',
186-
// },
186+
const spec: OpenApiV3_0_X = {
187+
info: {
188+
title: '',
189+
version: '1',
190+
},
187191
openapi: '3.0.4',
192+
paths: {},
188193
};
189194
parseExperimental({
190195
// @ts-ignore
191196
config: {},
192197
parserConfig,
193198
spec,
194199
});
195-
expect(parseV3_0_0).toHaveBeenCalled();
200+
expect(parseV3_0_X).toHaveBeenCalled();
196201
});
197202

198203
it('handles OpenAPI 3.1.0', () => {
199-
const spec: OpenApiV3_1_0 = {
204+
const spec: OpenApiV3_1_X = {
200205
info: {
201206
title: '',
202207
version: '1',
@@ -209,11 +214,11 @@ describe('experimentalParser', () => {
209214
parserConfig,
210215
spec,
211216
});
212-
expect(parseV3_1_0).toHaveBeenCalled();
217+
expect(parseV3_1_X).toHaveBeenCalled();
213218
});
214219

215220
it('handles OpenAPI 3.1.1', () => {
216-
const spec: OpenApiV3_1_0 = {
221+
const spec: OpenApiV3_1_X = {
217222
info: {
218223
title: '',
219224
version: '1',
@@ -226,6 +231,6 @@ describe('experimentalParser', () => {
226231
parserConfig,
227232
spec,
228233
});
229-
expect(parseV3_1_0).toHaveBeenCalled();
234+
expect(parseV3_1_X).toHaveBeenCalled();
230235
});
231236
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export interface EnumExtensions {
2+
/**
3+
* `x-enum-descriptions` are {@link https://stackoverflow.com/a/66471626 supported} by OpenAPI Generator.
4+
*/
5+
'x-enum-descriptions'?: ReadonlyArray<string>;
6+
/**
7+
* `x-enum-varnames` are {@link https://stackoverflow.com/a/66471626 supported} by OpenAPI Generator.
8+
*/
9+
'x-enum-varnames'?: ReadonlyArray<string>;
10+
/**
11+
* {@link https://github.com/RicoSuter/NSwag NSwag} generates `x-enumNames` field containing custom enum names.
12+
*/
13+
'x-enumNames'?: ReadonlyArray<string>;
14+
}

Diff for: packages/openapi-ts/src/openApi/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IRContext } from '../ir/context';
22
import type { Config } from '../types/config';
3-
import { type OpenApiV3_0_0, parseV3_0_0 } from './3.0.x';
4-
import { type OpenApiV3_1_0, parseV3_1_0 } from './3.1.x';
3+
import { type OpenApiV3_0_X, parseV3_0_X } from './3.0.x';
4+
import { type OpenApiV3_1_X, parseV3_1_X } from './3.1.x';
55
import type { Client } from './common/interfaces/client';
66
import type { OpenApi } from './common/interfaces/OpenApi';
77
import type { ParserConfig } from './config';
@@ -73,19 +73,19 @@ export const parseExperimental = ({
7373
spec: spec as Record<string, any>,
7474
});
7575

76-
const ctx = context as IRContext<OpenApiV3_0_0 | OpenApiV3_1_0>;
76+
const ctx = context as IRContext<OpenApiV3_0_X | OpenApiV3_1_X>;
7777
switch (ctx.spec.openapi) {
7878
// TODO: parser - handle Swagger 2.0
7979
case '3.0.0':
8080
case '3.0.1':
8181
case '3.0.2':
8282
case '3.0.3':
8383
case '3.0.4':
84-
parseV3_0_0(context as IRContext<OpenApiV3_0_0>);
84+
parseV3_0_X(context as IRContext<OpenApiV3_0_X>);
8585
break;
8686
case '3.1.0':
8787
case '3.1.1':
88-
parseV3_1_0(context as IRContext<OpenApiV3_1_0>);
88+
parseV3_1_X(context as IRContext<OpenApiV3_1_X>);
8989
break;
9090
default:
9191
// TODO: parser - uncomment after removing legacy parser.

0 commit comments

Comments
 (0)