File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
test/transforms/components Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -865,4 +865,48 @@ describe('parseComponents method', () => {
865
865
const result = parseComponents ( { } , parsedJSDocs ) ;
866
866
expect ( result ) . toEqual ( expected ) ;
867
867
} ) ;
868
+
869
+ it ( 'Should parse jsdoc component spec dictionary' , ( ) => {
870
+ const jsodInput = [ `
871
+ /**
872
+ * Profile
873
+ * @typedef {object} Profile
874
+ *
875
+ * @property {string} email
876
+ */
877
+ ` ,
878
+ `
879
+ /**
880
+ * Profiles dict
881
+ * @typedef {Dictionary<Profile>} Profiles
882
+ */
883
+ ` ] ;
884
+ const expected = {
885
+ components : {
886
+ schemas : {
887
+ Profile : {
888
+ type : 'object' ,
889
+ description : 'Profile' ,
890
+ properties : {
891
+ email : {
892
+ type : 'string' ,
893
+ description : '' ,
894
+ } ,
895
+ } ,
896
+ } ,
897
+ Profiles : {
898
+ type : 'object' ,
899
+ description : 'Profiles dict' ,
900
+ properties : { } ,
901
+ additionalProperties : {
902
+ $ref : '#/components/schemas/Profile' ,
903
+ } ,
904
+ } ,
905
+ } ,
906
+ } ,
907
+ } ;
908
+ const parsedJSDocs = jsdocInfo ( ) ( jsodInput ) ;
909
+ const result = parseComponents ( { } , parsedJSDocs ) ;
910
+ expect ( result ) . toEqual ( expected ) ;
911
+ } ) ;
868
912
} ) ;
Original file line number Diff line number Diff line change @@ -64,6 +64,18 @@ const getRequiredProperties = properties => (
64
64
65
65
const formatRequiredProperties = requiredProperties => requiredProperties . map ( getPropertyName ) ;
66
66
67
+ const addDictionaryAdditionalProperties = typedef => {
68
+ if ( ! typedef . type . expression || typedef . type . expression . name !== 'Dictionary' ) {
69
+ return { } ;
70
+ }
71
+
72
+ return {
73
+ additionalProperties : {
74
+ $ref : `#/components/schemas/${ typedef . type . applications [ 0 ] . name } ` ,
75
+ } ,
76
+ } ;
77
+ } ;
78
+
67
79
const parseSchema = ( schema , options = { } ) => {
68
80
const typedef = getTagInfo ( schema . tags , 'typedef' ) ;
69
81
const propertyValues = getTagsInfo ( schema . tags , 'property' ) ;
@@ -88,6 +100,7 @@ const parseSchema = (schema, options = {}) => {
88
100
} : { } ) ,
89
101
...( format ? { format } : { } ) ,
90
102
...addEnumValues ( enumValues ) ,
103
+ ...addDictionaryAdditionalProperties ( typedef ) ,
91
104
...( jsonOptions || { } ) ,
92
105
} ,
93
106
} ;
You can’t perform that action at this time.
0 commit comments