Skip to content

Commit e0dfbdf

Browse files
authored
Merge pull request #17 from DavidBiesack/issue-16-remove-webhooks
Add convert code to remove OAS 3.1 webhooks
2 parents 7e30ca0 + c9dd19d commit e0dfbdf

6 files changed

Lines changed: 54 additions & 5 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ in the `$ref` target.)
211211

212212
Remove `info.license.identifier`.
213213

214+
### ⤓ `webhooks`
215+
216+
Remove the `webhooks` object, if present.
217+
214218
### ⤓ JSON Schema related changes
215219

216220
OAS 3.0 uses an earlier JSON Schema version (Draft 4). The tool convert `examples`

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@apiture/openapi-down-convert",
3-
"version": "0.10.0",
3+
"version": "0.11.0",
44
"description": "Tool to down convert OpenAPI 3.1 to OpenAPI 3.0",
55
"main": "lib/src/index.js",
66
"bin": {

src/converter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export class Converter {
144144
this.convertJsonSchemaContentMediaType();
145145
this.convertConstToEnum();
146146
this.convertNullableTypeArray();
147+
this.removeWebhooksObject();
147148
this.removeUnsupportedSchemaKeywords();
148149
if (this.convertSchemaComments) {
149150
this.renameSchema$comment();
@@ -243,6 +244,12 @@ export class Converter {
243244
visitSchemaObjects(this.openapi30, schemaVisitor);
244245
}
245246

247+
removeWebhooksObject() {
248+
if (Object.hasOwnProperty.call(this.openapi30, 'webhooks')) {
249+
this.log(`Deleted webhooks object`);
250+
delete this.openapi30['webhooks'];
251+
}
252+
}
246253
removeUnsupportedSchemaKeywords() {
247254
const keywordsToRemove = ['$id', '$schema', 'unevaluatedProperties'];
248255
const schemaVisitor: SchemaVisitor = (schema: SchemaObject): SchemaObject => {

test/converter.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,43 @@ describe('resolver test suite', () => {
355355
done();
356356
});
357357

358+
359+
test('Remove webhooks object', (done) => {
360+
const input = {
361+
openapi: '3.1.0',
362+
webhooks: {
363+
newThing: {
364+
post: {
365+
requestBody: {
366+
description: 'Information about a new thing in the system',
367+
content: {
368+
'application/json': {
369+
schema: {
370+
$ref: '#/components/schemas/newThing'
371+
}
372+
}
373+
}
374+
},
375+
responses: {
376+
200: {
377+
description: 'Return a 200 status to indicate that the data was received successfully'
378+
}
379+
}
380+
}
381+
}
382+
}
383+
};
384+
385+
const expected = {
386+
openapi: '3.0.3'
387+
};
388+
389+
const converter = new Converter(input, { verbose: true });
390+
const converted: any = converter.convert();
391+
expect(converted).toEqual(expected);
392+
done();
393+
});
394+
358395
test('Remove $id and $schema keywords', (done) => {
359396
// const sourceFileName = path.join(__dirname, 'data/root.yaml'); // __dirname is the test dir
360397
const input = {

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
"compilerOptions": {
33
"module": "commonjs",
44
"target": "ES2018",
5-
"lib" : ["ES2020"],
5+
"lib" : ["ES2020", "DOM"],
66
"outDir": "./lib",
77
"moduleResolution": "node",
88
"removeComments": true,
99
"sourceMap": true,
1010
"noUnusedLocals": true,
1111
"skipLibCheck": true,
1212
"resolveJsonModule": true,
13-
"declaration": true
13+
"declaration": true,
14+
"types" : [ "node" ]
1415
},
1516
"include": ["src/**/*"],
1617
"exclude": ["node_modules", "lib"],

0 commit comments

Comments
 (0)