1
- const { createMapOfType, getMapKeyOfType , addExtensions } = require ( '../utils' ) ;
1
+ const { createMapOfType, getMapValueOfType , addExtensions } = require ( '../utils' ) ;
2
2
const Base = require ( './base' ) ;
3
3
const Info = require ( './info' ) ;
4
4
const Server = require ( './server' ) ;
5
5
const Channel = require ( './channel' ) ;
6
6
const Components = require ( './components' ) ;
7
7
const Tag = require ( './tag' ) ;
8
+
8
9
const xParserMessageName = 'x-parser-message-name' ;
9
10
const xParserSchemaId = 'x-parser-schema-id' ;
10
11
@@ -66,7 +67,7 @@ class AsyncAPIDocument extends Base {
66
67
* @returns {Server }
67
68
*/
68
69
server ( name ) {
69
- return getMapKeyOfType ( this . _json . servers , name , Server ) ;
70
+ return getMapValueOfType ( this . _json . servers , name , Server ) ;
70
71
}
71
72
72
73
/**
@@ -96,7 +97,7 @@ class AsyncAPIDocument extends Base {
96
97
* @returns {Channel }
97
98
*/
98
99
channel ( name ) {
99
- return getMapKeyOfType ( this . _json . channels , name , Channel , this ) ;
100
+ return getMapValueOfType ( this . _json . channels , name , Channel , this ) ;
100
101
}
101
102
102
103
/**
@@ -199,7 +200,7 @@ function assignNameToComponentMessages(doc) {
199
200
if ( doc . hasComponents ( ) ) {
200
201
for ( const [ key , m ] of Object . entries ( doc . components ( ) . messages ( ) ) ) {
201
202
if ( m . name ( ) === undefined ) {
202
- m . json ( ) [ xParserMessageName ] = key ;
203
+ m . json ( ) [ String ( xParserMessageName ) ] = key ;
203
204
}
204
205
}
205
206
}
@@ -214,7 +215,7 @@ function assignUidToParameterSchemas(doc) {
214
215
doc . channelNames ( ) . forEach ( channelName => {
215
216
const channel = doc . channel ( channelName ) ;
216
217
for ( const [ parameterKey , parameterSchema ] of Object . entries ( channel . parameters ( ) ) ) {
217
- parameterSchema . json ( ) [ xParserSchemaId ] = parameterKey ;
218
+ parameterSchema . json ( ) [ String ( xParserSchemaId ) ] = parameterKey ;
218
219
}
219
220
} ) ;
220
221
}
@@ -227,7 +228,7 @@ function assignUidToParameterSchemas(doc) {
227
228
function assignUidToComponentSchemas ( doc ) {
228
229
if ( doc . hasComponents ( ) ) {
229
230
for ( const [ key , s ] of Object . entries ( doc . components ( ) . schemas ( ) ) ) {
230
- s . json ( ) [ xParserSchemaId ] = key ;
231
+ s . json ( ) [ String ( xParserSchemaId ) ] = key ;
231
232
}
232
233
}
233
234
}
@@ -257,7 +258,7 @@ function assignNameToAnonymousMessages(doc) {
257
258
function addNameToKey ( messages , number ) {
258
259
messages . forEach ( m => {
259
260
if ( m . name ( ) === undefined ) {
260
- m . json ( ) [ xParserMessageName ] = `<anonymous-message-${ number } >` ;
261
+ m . json ( ) [ String ( xParserMessageName ) ] = `<anonymous-message-${ number } >` ;
261
262
}
262
263
} ) ;
263
264
}
@@ -362,7 +363,7 @@ function assignIdToAnonymousSchemas(doc) {
362
363
let anonymousSchemaCounter = 0 ;
363
364
const callback = ( schema ) => {
364
365
if ( ! schema . uid ( ) ) {
365
- schema . json ( ) [ xParserSchemaId ] = `<anonymous-schema-${ ++ anonymousSchemaCounter } >` ;
366
+ schema . json ( ) [ String ( xParserSchemaId ) ] = `<anonymous-schema-${ ++ anonymousSchemaCounter } >` ;
366
367
}
367
368
} ;
368
369
schemaDocument ( doc , callback ) ;
0 commit comments