Skip to content

Commit 9479e54

Browse files
authored
Upgrade openapi to 3.1 (#2614)
1 parent 88be161 commit 9479e54

File tree

132 files changed

+3315
-3790
lines changed

Some content is hidden

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

132 files changed

+3315
-3790
lines changed

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ catalog:
2121
typescript: 5.9.3
2222
vitest: 4.0.8
2323
'@types/node': 22.18.12
24+
'@scalar/openapi-types': 0.5.2
2425

2526
# using named catalogs to align packages in /tests with /samples
2627
catalogs:

docs/src/pages/reference/cli.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ $ orval --config ./api/orval.config.js
4343
4444
### Project
4545
46-
The `--project` option, shorthand `-p`, can be used to focus on one project of your Orval config.
46+
The `--project` option, shorthand `-p`, can be used to focus on projects of your Orval config.
4747
4848
```bash
4949
$ orval --project petstore
50+
$ orval --project dogstore catstore
5051
```
5152
5253
### Watch

docs/src/pages/reference/configuration/input.mdx

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,6 @@ export default defineConfig({
2121
});
2222
```
2323

24-
Using a secure URL target with authentication:
25-
26-
```js
27-
import { defineConfig } from 'orval';
28-
29-
export default defineConfig({
30-
petstore: {
31-
input: {
32-
target: 'https://example.com/api-docs/v2/swagger.yaml',
33-
parserOptions: {
34-
resolve: {
35-
http: {
36-
headers: {
37-
Authorization:
38-
'Basic ' + Buffer.from('username:password').toString('base64'),
39-
},
40-
},
41-
},
42-
},
43-
},
44-
},
45-
});
46-
```
47-
48-
## validation
49-
50-
Type: `Boolean | Object`
51-
52-
Default value: `false`.
53-
54-
To enforce the quality of your OpenAPI specification, Orval supports validating specifications with the <a href="https://github.com/IBM/openapi-validator" target="_blank">OpenAPI linter from IBM</a>.
55-
56-
Specifying `true` will by default use the <a href="https://github.com/IBM/openapi-validator/blob/main/docs/ibm-cloud-rules.md"><em>IBM Cloud Validation Ruleset</em></a>.
57-
Specifying an `Object` will use the provided ruleset instead. Learn more about creating rulesets <a href="https://docs.stoplight.io/docs/spectral/aa15cdee143a1-java-script-ruleset-format">here</a>.
58-
59-
```js
60-
import { defineConfig } from 'orval';
61-
62-
export default defineConfig({
63-
petstore: {
64-
input: {
65-
validation: true,
66-
},
67-
},
68-
});
69-
```
70-
7124
## override
7225

7326
Type: `Object`.
@@ -172,53 +125,3 @@ export default defineConfig({
172125
},
173126
});
174127
```
175-
176-
## converterOptions
177-
178-
Type: `Object`.
179-
180-
Default Value: `{}`.
181-
182-
Orval converts Swagger 2.0 definitions into OpenAPI 3.0.x using [swagger2openapi](https://github.com/Mermade/oas-kit/tree/main/packages/swagger2openapi). Use the `converterOptions` property to provide custom config for that. See the available options [here](https://github.com/orval-labs/orval/blob/next/src/types/swagger2openapi.d.ts#L10).
183-
184-
Example:
185-
186-
```js
187-
import { defineConfig } from 'orval';
188-
189-
export default defineConfig({
190-
petstore: {
191-
input: {
192-
converterOptions: {
193-
patch: true,
194-
indent: 2,
195-
},
196-
},
197-
},
198-
});
199-
```
200-
201-
## parserOptions
202-
203-
Type: `Object`.
204-
205-
Default Value: `{ resolve: { github: githubResolver, http: { safeUrlResolver: false } }, validate: true }`.
206-
207-
Orval utilizes a parser to process multiple file specifications. This behavior can be customized using the `parserOptions` property. See the [available options](https://apidevtools.com/swagger-parser/options.html) for configuration.
208-
By default, Orval includes a GitHub parser, but you can add your own for private specifications or other specific needs.
209-
210-
The specification is automatically validated by default.
211-
212-
```js
213-
import { defineConfig } from 'orval';
214-
215-
export default defineConfig({
216-
petstore: {
217-
input: {
218-
parserOptions: {
219-
resolve: { gitlab: gitlabResolver },
220-
},
221-
},
222-
},
223-
});
224-
```

packages/core/package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,14 @@
2727
"@types/debug": "^4.1.12",
2828
"@types/esutils": "^2.0.2",
2929
"@types/fs-extra": "^11.0.4",
30-
"@types/swagger2openapi": "^7.0.4",
3130
"eslint": "catalog:",
32-
"openapi-types": "^12.1.3",
3331
"rimraf": "catalog:",
3432
"tsdown": "catalog:",
3533
"typescript": "catalog:",
3634
"vitest": "catalog:"
3735
},
3836
"dependencies": {
39-
"@apidevtools/swagger-parser": "^12.1.0",
40-
"@ibm-cloud/openapi-ruleset": "^1.33.1",
41-
"@stoplight/spectral-core": "^1.20.0",
37+
"@scalar/openapi-types": "catalog:",
4238
"acorn": "^8.15.0",
4339
"chalk": "^5.6.2",
4440
"compare-versions": "^6.1.1",
@@ -47,9 +43,7 @@
4743
"esutils": "2.0.3",
4844
"fs-extra": "^11.3.2",
4945
"globby": "16.0.0",
50-
"openapi3-ts": "4.5.0",
5146
"remeda": "^2.32.0",
52-
"swagger2openapi": "^7.0.8",
5347
"typedoc": "^0.28.14"
5448
},
5549
"stableVersion": "8.0.0-rc.1"
Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,58 @@
1-
import type {
2-
ComponentsObject,
3-
ReferenceObject,
4-
RequestBodyObject,
5-
ResponseObject,
6-
} from 'openapi3-ts/oas30';
7-
import { isEmptyish } from 'remeda';
1+
import { entries, isEmptyish } from 'remeda';
82

93
import { getResReqTypes } from '../getters';
10-
import type { ContextSpecs, GeneratorSchema } from '../types';
4+
import type {
5+
ContextSpec,
6+
GeneratorSchema,
7+
OpenApiComponentsObject,
8+
} from '../types';
119
import { jsDoc, pascal, sanitize } from '../utils';
1210

13-
export const generateComponentDefinition = (
11+
export function generateComponentDefinition(
1412
responses:
15-
| ComponentsObject['responses']
16-
| ComponentsObject['requestBodies'] = {},
17-
context: ContextSpecs,
13+
| OpenApiComponentsObject['responses']
14+
| OpenApiComponentsObject['requestBodies'] = {},
15+
context: ContextSpec,
1816
suffix: string,
19-
): GeneratorSchema[] => {
17+
): GeneratorSchema[] {
2018
if (isEmptyish(responses)) {
2119
return [];
2220
}
2321

24-
return Object.entries(responses).reduce<GeneratorSchema[]>(
25-
(
26-
acc,
27-
[name, response]: [
28-
string,
29-
ReferenceObject | RequestBodyObject | ResponseObject,
30-
],
31-
) => {
32-
const allResponseTypes = getResReqTypes(
33-
[[suffix, response]],
34-
name,
35-
context,
36-
'void',
37-
);
38-
39-
const imports = allResponseTypes.flatMap(({ imports }) => imports);
40-
const schemas = allResponseTypes.flatMap(({ schemas }) => schemas);
41-
42-
const type = allResponseTypes.map(({ value }) => value).join(' | ');
43-
44-
const modelName = sanitize(`${pascal(name)}${suffix}`, {
45-
underscore: '_',
46-
whitespace: '_',
47-
dash: true,
48-
es5keyword: true,
49-
es5IdentifierName: true,
22+
const generatorSchemas: GeneratorSchema[] = [];
23+
for (const [name, response] of entries(responses)) {
24+
const allResponseTypes = getResReqTypes(
25+
[[suffix, response]],
26+
name,
27+
context,
28+
'void',
29+
);
30+
31+
const imports = allResponseTypes.flatMap(({ imports }) => imports);
32+
const schemas = allResponseTypes.flatMap(({ schemas }) => schemas);
33+
34+
const type = allResponseTypes.map(({ value }) => value).join(' | ');
35+
36+
const modelName = sanitize(`${pascal(name)}${suffix}`, {
37+
underscore: '_',
38+
whitespace: '_',
39+
dash: true,
40+
es5keyword: true,
41+
es5IdentifierName: true,
42+
});
43+
const doc = jsDoc(response);
44+
const model = `${doc}export type ${modelName} = ${type || 'unknown'};\n`;
45+
46+
generatorSchemas.push(...schemas);
47+
48+
if (modelName !== type) {
49+
generatorSchemas.push({
50+
name: modelName,
51+
model,
52+
imports,
5053
});
51-
const doc = jsDoc(response as ResponseObject | RequestBodyObject);
52-
const model = `${doc}export type ${modelName} = ${type || 'unknown'};\n`;
53-
54-
acc.push(...schemas);
55-
56-
if (modelName !== type) {
57-
acc.push({
58-
name: modelName,
59-
model,
60-
imports,
61-
});
62-
}
54+
}
55+
}
6356

64-
return acc;
65-
},
66-
[],
67-
);
68-
};
57+
return generatorSchemas;
58+
}

0 commit comments

Comments
 (0)