File tree Expand file tree Collapse file tree 3 files changed +61
-7
lines changed
test/transforms/components Expand file tree Collapse file tree 3 files changed +61
-7
lines changed Original file line number Diff line number Diff line change 1+ {
2+ // Use IntelliSense to learn about possible attributes.
3+ // Hover to view descriptions of existing attributes.
4+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+ "version" : " 0.2.0" ,
6+ "configurations" : [
7+ {
8+ "name" : " Debug Jest Tests" ,
9+ "type" : " node" ,
10+ "request" : " launch" ,
11+ "runtimeArgs" : [
12+ " --inspect-brk" ,
13+ " ${workspaceRoot}/node_modules/.bin/jest" ,
14+ " --runInBand"
15+ ],
16+ "console" : " integratedTerminal" ,
17+ "internalConsoleOptions" : " neverOpen" ,
18+ "port" : 9229
19+ }
20+ ]
21+ }
Original file line number Diff line number Diff line change @@ -909,4 +909,30 @@ describe('parseComponents method', () => {
909909 const result = parseComponents ( { } , parsedJSDocs ) ;
910910 expect ( result ) . toEqual ( expected ) ;
911911 } ) ;
912+
913+ it ( 'Should parse jsdoc component spec record type' , ( ) => {
914+ const jsodInput = [ `
915+ /**
916+ * Records dict
917+ * @typedef {Dictionary<string>} Records map
918+ */
919+ ` ] ;
920+ const expected = {
921+ components : {
922+ schemas : {
923+ Records : {
924+ type : 'object' ,
925+ description : 'Records dict' ,
926+ properties : { } ,
927+ additionalProperties : {
928+ type : 'string' ,
929+ } ,
930+ } ,
931+ } ,
932+ } ,
933+ } ;
934+ const parsedJSDocs = jsdocInfo ( ) ( jsodInput ) ;
935+ const result = parseComponents ( { } , parsedJSDocs ) ;
936+ expect ( result ) . toEqual ( expected ) ;
937+ } ) ;
912938} ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const { refSchema, formatRefSchema } = require('../utils/refSchema');
44const addEnumValues = require ( '../utils/enumValues' ) ;
55const formatDescription = require ( '../utils/formatDescription' ) ;
66const combineSchema = require ( '../utils/combineSchema' ) ;
7+ const validateTypes = require ( '../utils/validateTypes' ) ;
78
89const REQUIRED = 'required' ;
910
@@ -65,15 +66,21 @@ const getRequiredProperties = properties => (
6566const formatRequiredProperties = requiredProperties => requiredProperties . map ( getPropertyName ) ;
6667
6768const addDictionaryAdditionalProperties = typedef => {
68- if ( ! typedef . type . expression || typedef . type . expression . name !== 'Dictionary' ) {
69- return { } ;
69+ if (
70+ typedef . type . expression
71+ && typedef . type . expression . name === 'Dictionary'
72+ ) {
73+ const typeName = typedef . type . applications [ 0 ] . name ;
74+ const isPrimitive = validateTypes ( typeName ) ;
75+
76+ return {
77+ additionalProperties : {
78+ ...( isPrimitive ? { type : typeName } : { $ref : `#/components/schemas/${ typeName } ` } ) ,
79+ } ,
80+ } ;
7081 }
7182
72- return {
73- additionalProperties : {
74- $ref : `#/components/schemas/${ typedef . type . applications [ 0 ] . name } ` ,
75- } ,
76- } ;
83+ return { } ;
7784} ;
7885
7986const parseSchema = ( schema , options = { } ) => {
You can’t perform that action at this time.
0 commit comments