Skip to content

Commit a10d09e

Browse files
committed
strip contentMediaType from schemas; add test
1 parent c9dd19d commit a10d09e

5 files changed

Lines changed: 50 additions & 3 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
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.11.0",
3+
"version": "0.12.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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export class Converter {
251251
}
252252
}
253253
removeUnsupportedSchemaKeywords() {
254-
const keywordsToRemove = ['$id', '$schema', 'unevaluatedProperties'];
254+
const keywordsToRemove = ['$id', '$schema', 'unevaluatedProperties', 'contentMediaType'];
255255
const schemaVisitor: SchemaVisitor = (schema: SchemaObject): SchemaObject => {
256256
keywordsToRemove.forEach((key) => {
257257
if (schema.hasOwnProperty(key)) {

test/converter.spec.ts

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

358+
test('Remove contentMediaType keywords', (done) => {
359+
const input = {
360+
openapi: '3.1.0',
361+
components: {
362+
schemas: {
363+
a: {
364+
type: 'object',
365+
unevaluatedProperties: false,
366+
properties: {
367+
b: {
368+
type: 'string',
369+
contentMediaType: 'application/pdf',
370+
maxLength: 5000000
371+
},
372+
},
373+
},
374+
},
375+
},
376+
};
377+
const expected = {
378+
openapi: '3.0.3',
379+
components: {
380+
schemas: {
381+
a: {
382+
type: 'object',
383+
properties: {
384+
b: {
385+
type: 'string',
386+
maxLength: 5000000
387+
},
388+
},
389+
},
390+
},
391+
},
392+
};
393+
const converter = new Converter(input, { verbose: true });
394+
const converted: any = converter.convert();
395+
expect(converted).toEqual(expected);
396+
done();
397+
});
398+
358399

359400
test('Remove webhooks object', (done) => {
360401
const input = {

test/data/openapi.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ paths:
6363
application/json:
6464
schema:
6565
$ref: '#/components/schemas/preferences'
66+
application/pdf:
67+
schema:
68+
type: string
69+
contentMediaType: application/json
70+
contentEncoding: base64
71+
maxLength: 5000000
6672
'400':
6773
$ref: '#/components/responses/400'
6874
'401':

0 commit comments

Comments
 (0)