Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for OpenAPI 3.0.4 #3754

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ We'll be consolidating that soon. Just giving you the heads-up. You may see refe
The OpenAPI Specification has undergone multiple revisions since initial creation in 2010.
Compatibility between Swagger Client and the OpenAPI Specification is as follows:

Swagger Client Version | Release Date | OpenAPI Spec compatibility | Notes
------------------ |--------------|----------------------------------------| -----
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)
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)
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.
Swagger Client Version | Release Date | OpenAPI Spec compatibility | Notes
------------------ |--------------|-----------------------------------------------| -----
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)
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)
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)
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.

## Anonymized analytics

Expand Down
4 changes: 2 additions & 2 deletions docs/usage/http-client-for-oas-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ Property | Description
`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.
`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.

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

```yaml
openapi: 3.0.0
openapi: 3.0.4
info:
title: Testing API
version: 1.0.0
Expand Down
96 changes: 52 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@
"dependencies": {
"@babel/runtime-corejs3": "^7.22.15",
"@scarf/scarf": "=1.4.0",
"@swagger-api/apidom-core": ">=1.0.0-beta.3 <1.0.0-rc.0",
"@swagger-api/apidom-error": ">=1.0.0-beta.3 <1.0.0-rc.0",
"@swagger-api/apidom-json-pointer": ">=1.0.0-beta.3 <1.0.0-rc.0",
"@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-beta.3 <1.0.0-rc.0",
"@swagger-api/apidom-reference": ">=1.0.0-beta.3 <1.0.0-rc.0",
"@swagger-api/apidom-core": ">=1.0.0-beta.6 <1.0.0-rc.0",
"@swagger-api/apidom-error": ">=1.0.0-beta.6 <1.0.0-rc.0",
"@swagger-api/apidom-json-pointer": ">=1.0.0-beta.6 <1.0.0-rc.0",
"@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-beta.6 <1.0.0-rc.0",
"@swagger-api/apidom-reference": ">=1.0.0-beta.6 <1.0.0-rc.0",
"cookie": "~0.7.2",
"deepmerge": "~4.3.0",
"fast-json-patch": "^3.0.0-1",
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/openapi-predicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const isOpenAPI2 = (spec) => {
export const isOpenAPI30 = (spec) => {
try {
const { openapi } = spec;
return typeof openapi === 'string' && /^3\.0\.([0123])(?:-rc[012])?$/.test(openapi);
return typeof openapi === 'string' && /^3\.0\.(?:[1-9]\d*|0)$/.test(openapi);
} catch {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/subtree-resolver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// This is useful for cases where resolving your entire object is unnecessary
// and/or non-performant; we use this interface for lazily resolving operations
// and models in Swagger-UI, which allows us to handle larger definitions.
// and models in Swagger-UI, which allows us to handle larger OpenAPI descriptions.
//
// It's likely that Swagger-Client will rely entirely on lazy resolving in
// future versions.
Expand Down
2 changes: 1 addition & 1 deletion test/bugs/ui-4071.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { buildRequest } from '../../src/execute/index.js';

const spec = {
openapi: '3.0.0',
openapi: '3.0.4',
servers: [
{
url: 'https://workbcjobs.api.gov.bc.ca/v1',
Expand Down
6 changes: 3 additions & 3 deletions test/data/issue-1719-ref-object-reference.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.0
openapi: 3.0.4
servers:
- description: "mock definition for swagger-client issue #1719"
url: https://test.com/v1
Expand All @@ -7,7 +7,7 @@ info:
title: Test Defect
description: >-
A client side JS error occured when the throwError endpoint was expanded in
the UI Docs panel. This error was specifically visible when a $ref is seen
the UI Docs panel. This error was specifically visible when a $ref is seen
by the subtree resolver after an allOf or after an anyOf. E.g. the subtree
resolver was treating the $ref as a reference instead as an object.
paths:
Expand Down Expand Up @@ -38,7 +38,7 @@ components:
2_RefWithAllOf:
allOf:
- $ref: '#/components/schemas/3_InnerAllOfRef'

3_InnerAllOfRef:
type: object
properties:
Expand Down
4 changes: 2 additions & 2 deletions test/data/parameter-examples-with-refs.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.0
openapi: 3.0.4
info:
title: These $refs in parameter examples should not be resolved
version: 1.0.0
Expand Down Expand Up @@ -71,4 +71,4 @@ paths:
components:
schemas:
Foo:
type: string
type: string
2 changes: 1 addition & 1 deletion test/data/relative-server.openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: "3.0.0"
openapi: "3.0.4"
servers:
- url: "/v1/"
paths:
Expand Down
2 changes: 1 addition & 1 deletion test/data/sample-multipart-oas3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default {
openapi: '3.0.0',
openapi: '3.0.4',
servers: [
{
url: '/api/v1',
Expand Down
2 changes: 1 addition & 1 deletion test/data/sample-query-parameter-json.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.1
openapi: 3.0.4
info:
version: "0.0.1"
title: Test Defect
Expand Down
8 changes: 4 additions & 4 deletions test/execute/server-variable-encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { execute, buildRequest } from '../../src/execute/index.js';
describe('execute/serverVariableEncoder', () => {
test('should encode when encoder provided', () => {
const spec = {
openapi: '3.0.3',
openapi: '3.0.4',
servers: [
{
url: '{server}/v1',
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('execute/serverVariableEncoder', () => {

test('should not encode when encoder not provided', () => {
const spec = {
openapi: '3.0.3',
openapi: '3.0.4',
servers: [
{
url: '{server}/v1',
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('execute/serverVariableEncoder', () => {
describe('buildRequest/serverVariableEncoder', () => {
test('should encode when encoder provided', () => {
const spec = {
openapi: '3.0.3',
openapi: '3.0.4',
servers: [
{
url: '{server}/v1',
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('buildRequest/serverVariableEncoder', () => {

test('should not encode when encoder not provided', () => {
const spec = {
openapi: '3.0.3',
openapi: '3.0.4',
servers: [
{
url: '{server}/v1',
Expand Down
8 changes: 6 additions & 2 deletions test/helpers/openapi-predicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import {
describe('helpers', () => {
describe('OpenAPI predicates', () => {
describe('isOpenAPI30', () => {
test('should detect OpenAPI 3.0.x versions', () => {
test('should detect OpenAPI 3.0.x versions in forward compatible way', () => {
expect(isOpenAPI30({ openapi: '3.0.0' })).toBe(true);
expect(isOpenAPI30({ openapi: '3.0.1' })).toBe(true);
expect(isOpenAPI30({ openapi: '3.0.2' })).toBe(true);
expect(isOpenAPI30({ openapi: '3.0.3' })).toBe(true);
expect(isOpenAPI30({ openapi: '3.0.4' })).toBe(true);
expect(isOpenAPI30({ openapi: '3.0.25' })).toBe(true);
});

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

describe('isOpenAPI31', () => {
test('should detect OpenAPI 3.1.x versions', () => {
test('should detect OpenAPI 3.1.x versions in forward compatible way', () => {
expect(isOpenAPI31({ openapi: '3.1.0' })).toBe(true);
expect(isOpenAPI31({ openapi: '3.1.1' })).toBe(true);
expect(isOpenAPI31({ openapi: '3.1.25' })).toBe(true);
});

test('should reject other OpenAPI versions', () => {
Expand All @@ -52,6 +55,7 @@ describe('helpers', () => {
expect(isOpenAPI3({ openapi: '3.0.1' })).toBe(true);
expect(isOpenAPI3({ openapi: '3.0.2' })).toBe(true);
expect(isOpenAPI3({ openapi: '3.0.3' })).toBe(true);
expect(isOpenAPI3({ openapi: '3.0.4' })).toBe(true);
expect(isOpenAPI3({ openapi: '3.1.0' })).toBe(true);
expect(isOpenAPI3({ openapi: '3.1.1' })).toBe(true);
});
Expand Down
2 changes: 1 addition & 1 deletion test/http/http-multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ describe('buildRequest - openapi 3.0', () => {
describe('respect Encoding Object', () => {
test('Should be set to object in the style of deepObject', () => {
const spec = {
openapi: '3.0.0',
openapi: '3.0.4',
servers: [
{
url: 'http://petstore.swagger.io/v2',
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ describe('constructor', () => {

describe('skipNormalization', () => {
const spec = {
openapi: '3.0.0',
openapi: '3.0.4',
info: {
title: 'Cloudpotato - Medwork',
description: 'The Cloudpotato API',
Expand Down
2 changes: 1 addition & 1 deletion test/oas3/data/petstore-oas3.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
openapi: 3.0.0
openapi: 3.0.4
servers:
- url: http://petstore.swagger.io/v2
info:
Expand Down
Loading
Loading