Skip to content

Commit

Permalink
Merge pull request #17 from DavidBiesack/issue-16-remove-webhooks
Browse files Browse the repository at this point in the history
Add convert code to remove OAS 3.1 webhooks
  • Loading branch information
DavidBiesack authored Jan 30, 2024
2 parents 7e30ca0 + c9dd19d commit e0dfbdf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
7 changes: 7 additions & 0 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class Converter {
this.convertJsonSchemaContentMediaType();
this.convertConstToEnum();
this.convertNullableTypeArray();
this.removeWebhooksObject();
this.removeUnsupportedSchemaKeywords();
if (this.convertSchemaComments) {
this.renameSchema$comment();
Expand Down Expand Up @@ -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 => {
Expand Down
37 changes: 37 additions & 0 deletions test/converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
"compilerOptions": {
"module": "commonjs",
"target": "ES2018",
"lib" : ["ES2020"],
"lib" : ["ES2020", "DOM"],
"outDir": "./lib",
"moduleResolution": "node",
"removeComments": true,
"sourceMap": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"declaration": true
"declaration": true,
"types" : [ "node" ]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "lib"],
Expand Down

0 comments on commit e0dfbdf

Please sign in to comment.