@@ -121,6 +121,7 @@ export class Converter {
121121 this . convertConstToEnum ( ) ;
122122 this . convertNullableTypeArray ( ) ;
123123 this . removeUnsupportedSchemaKeywords ( ) ;
124+ this . renameSchema$comment ( ) ;
124125 return this . openapi30 ;
125126 }
126127
@@ -169,23 +170,15 @@ export class Converter {
169170 * Replace all `$comment` with `x-comment`
170171 */
171172 convertJsonSchemaComments ( ) {
172- const schemaVisitor : SchemaVisitor = ( schema : SchemaObject ) : SchemaObject => {
173- for ( const key in schema ) {
174- const subSchema = schema [ key ] ;
175- if ( subSchema !== null && typeof subSchema === 'object' ) {
176- if ( key === '$comment' ) {
177- const comment = schema [ '$comment' ] ;
178- if ( comment . length > 0 ) {
179- delete schema [ '$comment' ] ;
180- schema [ 'x-comment' ] = comment ;
181- this . log ( `Replaces $comment with x-comment. Comment:\n${ comment } ` ) ;
182- }
183- } else {
184- schema [ key ] = walkObject ( subSchema , schemaVisitor ) ;
185- }
186- }
173+ const schemaVisitor : SchemaVisitor =
174+ ( schema : SchemaObject ) : SchemaObject =>
175+ {
176+ if ( schema . hasOwnProperty ( '$comment' ) ) {
177+ schema [ 'x-comment' ] = schema [ '$comment' ] ;
178+ delete schema [ '$comment' ] ;
179+ this . log ( `schema $comment renamed to x-comment` ) ;
187180 }
188- return schema ;
181+ return this . walkNestedSchemaObjects ( schema , schemaVisitor ) ;
189182 } ;
190183 visitSchemaObjects ( this . openapi30 , schemaVisitor ) ;
191184 }
@@ -252,6 +245,21 @@ export class Converter {
252245 visitSchemaObjects ( this . openapi30 , schemaVisitor ) ;
253246 }
254247
248+ renameSchema$comment ( ) {
249+ const schemaVisitor : SchemaVisitor =
250+ ( schema : SchemaObject ) : SchemaObject =>
251+ {
252+ if ( schema . hasOwnProperty ( '$comment' ) ) {
253+ schema [ 'x-comment' ] = schema [ '$comment' ] ;
254+ delete schema [ '$comment' ] ;
255+ this . log ( `schema $comment renamed to x-comment` ) ;
256+ }
257+ return this . walkNestedSchemaObjects ( schema , schemaVisitor ) ;
258+ } ;
259+ visitSchemaObjects ( this . openapi30 , schemaVisitor ) ;
260+ }
261+
262+
255263 private json ( x ) {
256264 return JSON . stringify ( x , null , 2 ) ;
257265 }
0 commit comments