Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove propertyNames #31

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading