Skip to content

Commit 824adc9

Browse files
authored
feat: add support for OpenAPI 3.0.4 (#3754)
Refs #3753
1 parent b6af0cb commit 824adc9

29 files changed

+321
-168
lines changed

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ We'll be consolidating that soon. Just giving you the heads-up. You may see refe
2222
The OpenAPI Specification has undergone multiple revisions since initial creation in 2010.
2323
Compatibility between Swagger Client and the OpenAPI Specification is as follows:
2424

25-
Swagger Client Version | Release Date | OpenAPI Spec compatibility | Notes
26-
------------------ |--------------|----------------------------------------| -----
27-
3.19.x | 2023-01-23 | 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.1.0 | [tag v3.19.0-alpha.3](https://github.com/swagger-api/swagger-js/releases/tag/v3.19.0-alpha.3)
28-
3.10.x | 2020-01-17 | 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3 | [tag v3.10.0](https://github.com/swagger-api/swagger-js/tree/v3.10.0)
29-
2.1.32 | 2017-01-12 | 1.0, 1.1, 1.2 | [tag v2.1.32](https://github.com/swagger-api/swagger-js/tree/v2.1.32). This [release](https://github.com/swagger-api/swagger-js/releases/tag/v2.1.32) is only available on GitHub.
25+
Swagger Client Version | Release Date | OpenAPI Spec compatibility | Notes
26+
------------------ |--------------|-----------------------------------------------| -----
27+
3.33.x | 2024-12-30 | 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.1.0 | [tag v3.33.0](https://github.com/swagger-api/swagger-js/releases/tag/v3.33.0)
28+
3.19.x | 2023-01-23 | 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.1.0 | [tag v3.19.0-alpha.3](https://github.com/swagger-api/swagger-js/releases/tag/v3.19.0-alpha.3)
29+
3.10.x | 2020-01-17 | 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3 | [tag v3.10.0](https://github.com/swagger-api/swagger-js/tree/v3.10.0)
30+
2.1.32 | 2017-01-12 | 1.0, 1.1, 1.2 | [tag v2.1.32](https://github.com/swagger-api/swagger-js/tree/v2.1.32). This [release](https://github.com/swagger-api/swagger-js/releases/tag/v2.1.32) is only available on GitHub.
3031

3132
## Anonymized analytics
3233

docs/usage/http-client-for-oas-operations.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ Property | Description
3232
`contextUrl` | `String`. URL, e.g. `https://example.com`. Used in following situations: <br /><br />If `server` option is not matched and there is no `Server Object` defined in the definition, this URL will be prepended to every requested path.<br /><br />If matched `Server Object` is defined as relative URI Reference its `url` fixed field is resolved against `contenxtUrl`. Resolved URL will be prepended to every requested path.
3333
`baseURL` | `String`. URL (`https://example.com`) . Takes precedence over server and any defined servers in the Spec. It will be prepended to every requested path.
3434

35-
For all later references, we will always use following OpenAPI 3.0.0 definition when referring
35+
For all later references, we will always use following OpenAPI 3.0.4 definition when referring
3636
to a `spec`.
3737

3838
```yaml
39-
openapi: 3.0.0
39+
openapi: 3.0.4
4040
info:
4141
title: Testing API
4242
version: 1.0.0

package-lock.json

+52-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@
7474
"dependencies": {
7575
"@babel/runtime-corejs3": "^7.22.15",
7676
"@scarf/scarf": "=1.4.0",
77-
"@swagger-api/apidom-core": ">=1.0.0-beta.3 <1.0.0-rc.0",
78-
"@swagger-api/apidom-error": ">=1.0.0-beta.3 <1.0.0-rc.0",
79-
"@swagger-api/apidom-json-pointer": ">=1.0.0-beta.3 <1.0.0-rc.0",
80-
"@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-beta.3 <1.0.0-rc.0",
81-
"@swagger-api/apidom-reference": ">=1.0.0-beta.3 <1.0.0-rc.0",
77+
"@swagger-api/apidom-core": ">=1.0.0-beta.6 <1.0.0-rc.0",
78+
"@swagger-api/apidom-error": ">=1.0.0-beta.6 <1.0.0-rc.0",
79+
"@swagger-api/apidom-json-pointer": ">=1.0.0-beta.6 <1.0.0-rc.0",
80+
"@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-beta.6 <1.0.0-rc.0",
81+
"@swagger-api/apidom-reference": ">=1.0.0-beta.6 <1.0.0-rc.0",
8282
"cookie": "~0.7.2",
8383
"deepmerge": "~4.3.0",
8484
"fast-json-patch": "^3.0.0-1",

src/helpers/openapi-predicates.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const isOpenAPI2 = (spec) => {
99
export const isOpenAPI30 = (spec) => {
1010
try {
1111
const { openapi } = spec;
12-
return typeof openapi === 'string' && /^3\.0\.([0123])(?:-rc[012])?$/.test(openapi);
12+
return typeof openapi === 'string' && /^3\.0\.(?:[1-9]\d*|0)$/.test(openapi);
1313
} catch {
1414
return false;
1515
}

src/subtree-resolver/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//
1515
// This is useful for cases where resolving your entire object is unnecessary
1616
// and/or non-performant; we use this interface for lazily resolving operations
17-
// and models in Swagger-UI, which allows us to handle larger definitions.
17+
// and models in Swagger-UI, which allows us to handle larger OpenAPI descriptions.
1818
//
1919
// It's likely that Swagger-Client will rely entirely on lazy resolving in
2020
// future versions.

test/bugs/ui-4071.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { buildRequest } from '../../src/execute/index.js';
33

44
const spec = {
5-
openapi: '3.0.0',
5+
openapi: '3.0.4',
66
servers: [
77
{
88
url: 'https://workbcjobs.api.gov.bc.ca/v1',

test/data/issue-1719-ref-object-reference.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: 3.0.0
1+
openapi: 3.0.4
22
servers:
33
- description: "mock definition for swagger-client issue #1719"
44
url: https://test.com/v1
@@ -7,7 +7,7 @@ info:
77
title: Test Defect
88
description: >-
99
A client side JS error occured when the throwError endpoint was expanded in
10-
the UI Docs panel. This error was specifically visible when a $ref is seen
10+
the UI Docs panel. This error was specifically visible when a $ref is seen
1111
by the subtree resolver after an allOf or after an anyOf. E.g. the subtree
1212
resolver was treating the $ref as a reference instead as an object.
1313
paths:
@@ -38,7 +38,7 @@ components:
3838
2_RefWithAllOf:
3939
allOf:
4040
- $ref: '#/components/schemas/3_InnerAllOfRef'
41-
41+
4242
3_InnerAllOfRef:
4343
type: object
4444
properties:

test/data/parameter-examples-with-refs.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: 3.0.0
1+
openapi: 3.0.4
22
info:
33
title: These $refs in parameter examples should not be resolved
44
version: 1.0.0
@@ -71,4 +71,4 @@ paths:
7171
components:
7272
schemas:
7373
Foo:
74-
type: string
74+
type: string

test/data/relative-server.openapi.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: "3.0.0"
1+
openapi: "3.0.4"
22
servers:
33
- url: "/v1/"
44
paths:

test/data/sample-multipart-oas3.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default {
2-
openapi: '3.0.0',
2+
openapi: '3.0.4',
33
servers: [
44
{
55
url: '/api/v1',

test/data/sample-query-parameter-json.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: 3.0.1
1+
openapi: 3.0.4
22
info:
33
version: "0.0.1"
44
title: Test Defect

test/execute/server-variable-encoder.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { execute, buildRequest } from '../../src/execute/index.js';
33
describe('execute/serverVariableEncoder', () => {
44
test('should encode when encoder provided', () => {
55
const spec = {
6-
openapi: '3.0.3',
6+
openapi: '3.0.4',
77
servers: [
88
{
99
url: '{server}/v1',
@@ -44,7 +44,7 @@ describe('execute/serverVariableEncoder', () => {
4444

4545
test('should not encode when encoder not provided', () => {
4646
const spec = {
47-
openapi: '3.0.3',
47+
openapi: '3.0.4',
4848
servers: [
4949
{
5050
url: '{server}/v1',
@@ -86,7 +86,7 @@ describe('execute/serverVariableEncoder', () => {
8686
describe('buildRequest/serverVariableEncoder', () => {
8787
test('should encode when encoder provided', () => {
8888
const spec = {
89-
openapi: '3.0.3',
89+
openapi: '3.0.4',
9090
servers: [
9191
{
9292
url: '{server}/v1',
@@ -124,7 +124,7 @@ describe('buildRequest/serverVariableEncoder', () => {
124124

125125
test('should not encode when encoder not provided', () => {
126126
const spec = {
127-
openapi: '3.0.3',
127+
openapi: '3.0.4',
128128
servers: [
129129
{
130130
url: '{server}/v1',

test/helpers/openapi-predicates.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import {
99
describe('helpers', () => {
1010
describe('OpenAPI predicates', () => {
1111
describe('isOpenAPI30', () => {
12-
test('should detect OpenAPI 3.0.x versions', () => {
12+
test('should detect OpenAPI 3.0.x versions in forward compatible way', () => {
1313
expect(isOpenAPI30({ openapi: '3.0.0' })).toBe(true);
1414
expect(isOpenAPI30({ openapi: '3.0.1' })).toBe(true);
1515
expect(isOpenAPI30({ openapi: '3.0.2' })).toBe(true);
1616
expect(isOpenAPI30({ openapi: '3.0.3' })).toBe(true);
17+
expect(isOpenAPI30({ openapi: '3.0.4' })).toBe(true);
18+
expect(isOpenAPI30({ openapi: '3.0.25' })).toBe(true);
1719
});
1820

1921
test('should reject other OpenAPI versions', () => {
@@ -29,9 +31,10 @@ describe('helpers', () => {
2931
});
3032

3133
describe('isOpenAPI31', () => {
32-
test('should detect OpenAPI 3.1.x versions', () => {
34+
test('should detect OpenAPI 3.1.x versions in forward compatible way', () => {
3335
expect(isOpenAPI31({ openapi: '3.1.0' })).toBe(true);
3436
expect(isOpenAPI31({ openapi: '3.1.1' })).toBe(true);
37+
expect(isOpenAPI31({ openapi: '3.1.25' })).toBe(true);
3538
});
3639

3740
test('should reject other OpenAPI versions', () => {
@@ -52,6 +55,7 @@ describe('helpers', () => {
5255
expect(isOpenAPI3({ openapi: '3.0.1' })).toBe(true);
5356
expect(isOpenAPI3({ openapi: '3.0.2' })).toBe(true);
5457
expect(isOpenAPI3({ openapi: '3.0.3' })).toBe(true);
58+
expect(isOpenAPI3({ openapi: '3.0.4' })).toBe(true);
5559
expect(isOpenAPI3({ openapi: '3.1.0' })).toBe(true);
5660
expect(isOpenAPI3({ openapi: '3.1.1' })).toBe(true);
5761
});

test/http/http-multipart.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ describe('buildRequest - openapi 3.0', () => {
338338
describe('respect Encoding Object', () => {
339339
test('Should be set to object in the style of deepObject', () => {
340340
const spec = {
341-
openapi: '3.0.0',
341+
openapi: '3.0.4',
342342
servers: [
343343
{
344344
url: 'http://petstore.swagger.io/v2',

test/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ describe('constructor', () => {
748748

749749
describe('skipNormalization', () => {
750750
const spec = {
751-
openapi: '3.0.0',
751+
openapi: '3.0.4',
752752
info: {
753753
title: 'Cloudpotato - Medwork',
754754
description: 'The Cloudpotato API',

test/oas3/data/petstore-oas3.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
openapi: 3.0.0
2+
openapi: 3.0.4
33
servers:
44
- url: http://petstore.swagger.io/v2
55
info:

0 commit comments

Comments
 (0)