Skip to content

Commit

Permalink
feat(oas): support info extensions (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel A. White authored Aug 28, 2023
1 parent f131406 commit 26ac072
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 54 deletions.
6 changes: 6 additions & 0 deletions src/oas/__tests__/__snapshots__/service.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Object {
"url": "http://swagger.io",
},
"id": "abc",
"infoExtensions": Object {
"x-special-info": 27,
},
"license": Object {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html",
Expand Down Expand Up @@ -121,6 +124,9 @@ Object {
"url": "http://swagger.io",
},
"id": "abc",
"infoExtensions": Object {
"x-special-info": 27,
},
"license": Object {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html",
Expand Down
65 changes: 15 additions & 50 deletions src/oas/__tests__/fixtures/oas2-kitchen-sink.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"x-special-info": 27
},
"host": "petstore.swagger.io",
"basePath": "/v2",
Expand Down Expand Up @@ -46,27 +47,16 @@
}
}
],
"schemes": [
"https",
"http"
],
"schemes": ["https", "http"],
"paths": {
"/pets": {
"post": {
"tags": [
"pet"
],
"tags": ["pet"],
"summary": "Add a new pet to the store",
"description": "",
"operationId": "addPet",
"consumes": [
"application/json",
"application/xml"
],
"produces": [
"application/xml",
"application/json"
],
"consumes": ["application/json", "application/xml"],
"produces": ["application/xml", "application/json"],
"parameters": [
{
"in": "body",
Expand All @@ -85,10 +75,7 @@
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
"petstore_auth": ["write:pets", "read:pets"]
}
],
"x-test": true,
Expand Down Expand Up @@ -169,20 +156,12 @@
}
],
"put": {
"tags": [
"pet"
],
"tags": ["pet"],
"summary": "Update an existing pet",
"description": "",
"operationId": "updatePet",
"consumes": [
"application/json",
"application/xml"
],
"produces": [
"application/xml",
"application/json"
],
"consumes": ["application/json", "application/xml"],
"produces": ["application/xml", "application/json"],
"parameters": [
{
"in": "body",
Expand All @@ -207,10 +186,7 @@
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
"petstore_auth": ["write:pets", "read:pets"]
}
]
}
Expand Down Expand Up @@ -266,17 +242,10 @@
"status": {
"type": "string",
"description": "pet status in the store",
"enum": [
"available",
"pending",
"sold"
]
"enum": ["available", "pending", "sold"]
}
},
"required": [
"name",
"photoUrls"
]
"required": ["name", "photoUrls"]
},
"Error": {
"type": "object",
Expand All @@ -288,9 +257,7 @@
"type": "string"
}
},
"required": [
"code"
]
"required": ["code"]
},
"Category": {
"type": "object",
Expand All @@ -299,9 +266,7 @@
"type": "string"
}
},
"required": [
"name"
],
"required": ["name"],
"title": "Category"
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/oas/__tests__/fixtures/oas3-kitchen-sink.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"x-special-info": 27
},
"tags": [
{
Expand Down
1 change: 1 addition & 0 deletions src/oas/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const transformOasService: TranslateFunction<DeepPartial<OpenAPIObject> |

...toExternalDocs(document.externalDocs),
extensions: getExtensions(document),
infoExtensions: getExtensions(document.info),
};

if (isPlainObject(document.info) && hasXLogo(document.info)) {
Expand Down
1 change: 1 addition & 0 deletions src/oas2/__tests__/__fixtures__/id/bundled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default {
id: 'service_abc',
},
},
infoExtensions: {},
components: {
callbacks: [],
cookie: [],
Expand Down
2 changes: 2 additions & 0 deletions src/oas2/__tests__/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('bundleOas2Service', () => {
id: 'abc',
},
},
infoExtensions: {},
operations: [
{
id: 'http_operation-abc-patch-/users/{}',
Expand Down Expand Up @@ -241,6 +242,7 @@ describe('bundleOas2Service', () => {
hello: 'world',
},
},
infoExtensions: {},
operations: [
{
id: 'http_operation-abc-patch-/users/{}',
Expand Down
15 changes: 15 additions & 0 deletions src/oas2/__tests__/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('oas2 service', () => {
id: 'def',
},
},
infoExtensions: {},
});
});

Expand Down Expand Up @@ -55,6 +56,7 @@ describe('oas2 service', () => {
id: 'abc',
},
},
infoExtensions: {},
servers: [
{
id: expect.any(String),
Expand Down Expand Up @@ -86,6 +88,7 @@ describe('oas2 service', () => {
id: 'abc',
},
},
infoExtensions: {},
});
});

Expand Down Expand Up @@ -135,6 +138,7 @@ describe('oas2 service', () => {
id: 'abc',
},
},
infoExtensions: {},
});
});
describe('x-logo support', () => {
Expand Down Expand Up @@ -168,6 +172,14 @@ describe('oas2 service', () => {
id: 'abc',
},
},
infoExtensions: {
'x-logo': {
altText: 'altText',
href: 'https://stoplight.io',
url: 'http://petstore.swagger.io/v2',
backgroundColor: '#FFF000',
},
},
});
});
it('should provide default values for href and altText', () => {
Expand Down Expand Up @@ -199,6 +211,9 @@ describe('oas2 service', () => {
id: 'abc',
},
},
infoExtensions: {
'x-logo': {},
},
});
});
});
Expand Down
1 change: 1 addition & 0 deletions src/oas3/__tests__/__fixtures__/examples/bundled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ export default {
id: 'service_abc',
},
},
infoExtensions: {},
};
1 change: 1 addition & 0 deletions src/oas3/__tests__/__fixtures__/examples/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default [
id: 'service_abc',
},
},
infoExtensions: {},
},
{
id: 'http_operation-service_abc-post-/users/{}',
Expand Down
1 change: 1 addition & 0 deletions src/oas3/__tests__/__fixtures__/id/bundled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,5 @@ export default {
id: 'service_abc',
},
},
infoExtensions: {},
};
1 change: 1 addition & 0 deletions src/oas3/__tests__/__fixtures__/id/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default [
id: 'service_abc',
},
},
infoExtensions: {},
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,5 @@ export default {
id: 'service_abc',
},
},
infoExtensions: {},
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default [
id: 'service_abc',
},
},
infoExtensions: {},
},

/**
Expand Down
6 changes: 6 additions & 0 deletions src/oas3/__tests__/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ describe('bundleOas3Service', () => {
id: 'service_id',
},
},
infoExtensions: {},
});
});

Expand Down Expand Up @@ -402,6 +403,7 @@ describe('bundleOas3Service', () => {
operations: [],
version: '',
extensions: {},
infoExtensions: {},
});
});

Expand Down Expand Up @@ -462,6 +464,7 @@ describe('bundleOas3Service', () => {
operations: [],
version: '',
extensions: {},
infoExtensions: {},
components: {
callbacks: [],
cookie: [],
Expand Down Expand Up @@ -599,6 +602,7 @@ describe('bundleOas3Service', () => {
name: 'no-title',
version: '',
extensions: {},
infoExtensions: {},
components: {
callbacks: [],
cookie: [],
Expand Down Expand Up @@ -728,6 +732,7 @@ describe('bundleOas3Service', () => {
name: 'no-title',
version: '',
extensions: {},
infoExtensions: {},
components: {
callbacks: [],
cookie: [],
Expand Down Expand Up @@ -834,6 +839,7 @@ describe('bundleOas3Service', () => {
hello: 'world',
},
},
infoExtensions: {},
operations: [
{
id: 'http_operation-abc-patch-/users/{}',
Expand Down
Loading

0 comments on commit 26ac072

Please sign in to comment.