From 77fd0e39da7ea86b64dcde1e3ee147ded3410cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Vandecr=C3=A8me?= Date: Wed, 30 Oct 2024 14:48:29 +0100 Subject: [PATCH] Remove propertyNames --- README.md | 5 +++-- src/converter.ts | 2 +- test/converter.spec.ts | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index faf8790..d8e481d 100644 --- a/README.md +++ b/README.md @@ -450,8 +450,9 @@ Contributions welcome! `exclusiveMinimum` and `exclusiveMaximum`, `unevaluatedProperties`, - `patternProperties` - as defined in JSON Schema 2012-12; these are not supported in JSON Schema Draft 7 + `patternProperties`, + `propertyNames` + as defined in JSON Schema 2020-12; these are not supported in JSON Schema Draft 7 used in OAS 3.0 * Webhooks are not removed. Contributions welcome! * The tool only supports self-contained documents. It does not follow or resolve diff --git a/src/converter.ts b/src/converter.ts index 84b6c82..6d22bff 100644 --- a/src/converter.ts +++ b/src/converter.ts @@ -251,7 +251,7 @@ export class Converter { } } removeUnsupportedSchemaKeywords() { - const keywordsToRemove = ['$id', '$schema', 'unevaluatedProperties', 'contentMediaType', 'patternProperties']; + const keywordsToRemove = ['$id', '$schema', 'unevaluatedProperties', 'contentMediaType', 'patternProperties', 'propertyNames']; const schemaVisitor: SchemaVisitor = (schema: SchemaObject): SchemaObject => { keywordsToRemove.forEach((key) => { if (schema.hasOwnProperty(key)) { diff --git a/test/converter.spec.ts b/test/converter.spec.ts index 915eb57..38dbd10 100644 --- a/test/converter.spec.ts +++ b/test/converter.spec.ts @@ -404,6 +404,42 @@ describe('resolver test suite', () => { done(); }); + test('Remove propertyNames keywords', (done) => { + const input = { + openapi: '3.1.0', + components: { + schemas: { + a: { + type: "object", + propertyNames: { + pattern: "^[A-Za-z_][A-Za-z0-9_]*$", + }, + additionalProperties: { + type: "string", + } + }, + }, + }, + }; + const expected = { + openapi: '3.0.3', + components: { + schemas: { + a: { + type: "object", + additionalProperties: { + type: "string", + } + }, + }, + }, + }; + const converter = new Converter(input, { verbose: true }); + const converted: any = converter.convert(); + expect(converted).toEqual(expected); + done(); + }); + test('Remove contentMediaType keywords', (done) => { const input = { openapi: '3.1.0',