Skip to content

Commit

Permalink
Merge pull request #19 from DavidBiesack/issue-18-remove-contentMedia…
Browse files Browse the repository at this point in the history
…Type

strip contentMediaType from schemas; add test
  • Loading branch information
DavidBiesack authored Mar 13, 2024
2 parents e0dfbdf + a10d09e commit 997ed6f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion 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.11.0",
"version": "0.12.0",
"description": "Tool to down convert OpenAPI 3.1 to OpenAPI 3.0",
"main": "lib/src/index.js",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class Converter {
}
}
removeUnsupportedSchemaKeywords() {
const keywordsToRemove = ['$id', '$schema', 'unevaluatedProperties'];
const keywordsToRemove = ['$id', '$schema', 'unevaluatedProperties', 'contentMediaType'];
const schemaVisitor: SchemaVisitor = (schema: SchemaObject): SchemaObject => {
keywordsToRemove.forEach((key) => {
if (schema.hasOwnProperty(key)) {
Expand Down
41 changes: 41 additions & 0 deletions test/converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,47 @@ describe('resolver test suite', () => {
done();
});

test('Remove contentMediaType keywords', (done) => {
const input = {
openapi: '3.1.0',
components: {
schemas: {
a: {
type: 'object',
unevaluatedProperties: false,
properties: {
b: {
type: 'string',
contentMediaType: 'application/pdf',
maxLength: 5000000
},
},
},
},
},
};
const expected = {
openapi: '3.0.3',
components: {
schemas: {
a: {
type: 'object',
properties: {
b: {
type: 'string',
maxLength: 5000000
},
},
},
},
},
};
const converter = new Converter(input, { verbose: true });
const converted: any = converter.convert();
expect(converted).toEqual(expected);
done();
});


test('Remove webhooks object', (done) => {
const input = {
Expand Down
6 changes: 6 additions & 0 deletions test/data/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/preferences'
application/pdf:
schema:
type: string
contentMediaType: application/json
contentEncoding: base64
maxLength: 5000000
'400':
$ref: '#/components/responses/400'
'401':
Expand Down

0 comments on commit 997ed6f

Please sign in to comment.