diff --git a/README.md b/README.md index 68f2317..0fac95c 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,10 @@ in the `$ref` target.) Remove `info.license.identifier`. +### ⤓ `webhooks` + +Remove the `webhooks` object, if present. + ### ⤓ JSON Schema related changes OAS 3.0 uses an earlier JSON Schema version (Draft 4). The tool convert `examples` diff --git a/package-lock.json b/package-lock.json index 0049b85..d916752 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@apiture/openapi-down-convert", - "version": "0.10.0", + "version": "0.11.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@apiture/openapi-down-convert", - "version": "0.10.0", + "version": "0.11.0", "license": "ISC", "dependencies": { "commander": "^9.4.1", diff --git a/package.json b/package.json index cde1fa7..09634fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@apiture/openapi-down-convert", - "version": "0.10.0", + "version": "0.11.0", "description": "Tool to down convert OpenAPI 3.1 to OpenAPI 3.0", "main": "lib/src/index.js", "bin": { diff --git a/src/converter.ts b/src/converter.ts index 959d66d..4bab609 100644 --- a/src/converter.ts +++ b/src/converter.ts @@ -144,6 +144,7 @@ export class Converter { this.convertJsonSchemaContentMediaType(); this.convertConstToEnum(); this.convertNullableTypeArray(); + this.removeWebhooksObject(); this.removeUnsupportedSchemaKeywords(); if (this.convertSchemaComments) { this.renameSchema$comment(); @@ -243,6 +244,12 @@ export class Converter { visitSchemaObjects(this.openapi30, schemaVisitor); } + removeWebhooksObject() { + if (Object.hasOwnProperty.call(this.openapi30, 'webhooks')) { + this.log(`Deleted webhooks object`); + delete this.openapi30['webhooks']; + } + } removeUnsupportedSchemaKeywords() { const keywordsToRemove = ['$id', '$schema', 'unevaluatedProperties']; const schemaVisitor: SchemaVisitor = (schema: SchemaObject): SchemaObject => { diff --git a/test/converter.spec.ts b/test/converter.spec.ts index ccf0ae7..1c74e13 100644 --- a/test/converter.spec.ts +++ b/test/converter.spec.ts @@ -355,6 +355,43 @@ describe('resolver test suite', () => { done(); }); + + test('Remove webhooks object', (done) => { + const input = { + openapi: '3.1.0', + webhooks: { + newThing: { + post: { + requestBody: { + description: 'Information about a new thing in the system', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/newThing' + } + } + } + }, + responses: { + 200: { + description: 'Return a 200 status to indicate that the data was received successfully' + } + } + } + } + } + }; + + const expected = { + openapi: '3.0.3' + }; + + const converter = new Converter(input, { verbose: true }); + const converted: any = converter.convert(); + expect(converted).toEqual(expected); + done(); + }); + test('Remove $id and $schema keywords', (done) => { // const sourceFileName = path.join(__dirname, 'data/root.yaml'); // __dirname is the test dir const input = { diff --git a/tsconfig.json b/tsconfig.json index a146683..fdac8a4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "module": "commonjs", "target": "ES2018", - "lib" : ["ES2020"], + "lib" : ["ES2020", "DOM"], "outDir": "./lib", "moduleResolution": "node", "removeComments": true, @@ -10,7 +10,8 @@ "noUnusedLocals": true, "skipLibCheck": true, "resolveJsonModule": true, - "declaration": true + "declaration": true, + "types" : [ "node" ] }, "include": ["src/**/*"], "exclude": ["node_modules", "lib"],