Skip to content

Commit

Permalink
Remove propertyNames
Browse files Browse the repository at this point in the history
  • Loading branch information
avandecreme committed Oct 30, 2024
1 parent 831e627 commit 77fd0e3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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', 'contentMediaType', 'patternProperties'];
const keywordsToRemove = ['$id', '$schema', 'unevaluatedProperties', 'contentMediaType', 'patternProperties', 'propertyNames'];
const schemaVisitor: SchemaVisitor = (schema: SchemaObject): SchemaObject => {
keywordsToRemove.forEach((key) => {
if (schema.hasOwnProperty(key)) {
Expand Down
36 changes: 36 additions & 0 deletions test/converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 77fd0e3

Please sign in to comment.