Skip to content

Commit

Permalink
simplify schema $comment -> x-comment
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBiesack committed Nov 20, 2023
1 parent b1daa8f commit 9e25511
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,15 @@ export class Converter {
* Replace all `$comment` with `x-comment`
*/
convertJsonSchemaComments() {
const schemaVisitor: SchemaVisitor = (schema: SchemaObject): SchemaObject => {
for (const key in schema) {
const subSchema = schema[key];
if (subSchema !== null && typeof subSchema === 'object') {
if (key === '$comment') {
const comment = schema['$comment'];
if (comment.length > 0) {
delete schema['$comment'];
schema['x-comment'] = comment;
this.log(`Replaces $comment with x-comment. Comment:\n${comment}`);
}
} else {
schema[key] = walkObject(subSchema, schemaVisitor);
}
}
const schemaVisitor: SchemaVisitor =
(schema: SchemaObject): SchemaObject =>
{
if (schema.hasOwnProperty('$comment')) {
schema['x-comment'] = schema['$comment'];
delete schema['$comment'];
this.log(`schema $comment renamed to x-comment`);
}
return schema;
return this.walkNestedSchemaObjects(schema, schemaVisitor);
};
visitSchemaObjects(this.openapi30, schemaVisitor);
}
Expand Down

0 comments on commit 9e25511

Please sign in to comment.