@@ -23,8 +23,116 @@ function copyToClipboard(elId) {
23
23
return copyText . value ;
24
24
}
25
25
26
+ function getParamTypeInfo ( schema , overrideAttributes = null ) {
27
+ let returnObj = {
28
+ hasCircularRefs :schema . type === "circular" ,
29
+ format : schema . format ?schema . format :'' ,
30
+ pattern : ( schema . pattern && ! schema . enum ) ? schema . pattern :'' ,
31
+ readOnly : schema . readOnly ? '🆁\u00a0' : '' ,
32
+ writeOnly : schema . writeOnly ? '🆆\u00a0' : '' ,
33
+ depricated : schema . deprecated ? '❌\u00a0' : '' ,
34
+ default : schema . default == 0 ? '0 ' : ( schema . default ? schema . default : '' ) ,
35
+ type : '' ,
36
+ allowedValues :'' ,
37
+ constrain : '' ,
38
+ html : ''
39
+ } ;
40
+ if ( returnObj . hasCircularRefs ) {
41
+ return returnObj ;
42
+ }
43
+ // Set the Type
44
+ if ( schema . enum ) {
45
+ let opt = ""
46
+ schema . enum . map ( function ( v ) {
47
+ opt = opt + `${ v } , `
48
+ } ) ;
49
+ returnObj . type = 'enum' ;
50
+ returnObj . allowedValues = opt . slice ( 0 , - 2 ) ;
51
+ }
52
+ else if ( schema . type ) {
53
+ returnObj . type = schema . type ;
54
+ }
55
+
56
+ if ( schema . type === "array" && schema . items ) {
57
+ let arraySchema = schema . items ;
58
+ returnObj . type = `${ schema . type } of ${ arraySchema . type } ` ;
59
+ returnObj . default = arraySchema . default == 0 ? '0 ' : ( arraySchema . default ? arraySchema . default : '' ) ;
60
+ if ( arraySchema . enum ) {
61
+ let opt = ""
62
+ arraySchema . enum . map ( function ( v ) {
63
+ opt = opt + `${ v } , `
64
+ } ) ;
65
+ returnObj . allowedValues = opt . slice ( 0 , - 2 ) ;
66
+ }
67
+ }
68
+ else if ( schema . type === "integer" || schema . type === "number" ) {
69
+ if ( schema . minimum !== undefined && schema . maximum !== undefined ) {
70
+ returnObj . constrain = `${ schema . exclusiveMinimum ?">" :"" } ${ schema . minimum } \u00a0\u22ef\u00a0${ schema . exclusiveMaximum ?"<" :"" } \u00a0${ schema . maximum } `
71
+ }
72
+ else if ( schema . minimum !== undefined && schema . maximum === undefined ) {
73
+ returnObj . constrain = `${ schema . exclusiveMinimum ?">" :"≥" } ${ schema . minimum } `
74
+ }
75
+ else if ( schema . minimum === undefined && schema . maximum !== undefined ) {
76
+ returnObj . constrain = `${ schema . exclusiveMaximum ?"<" :"≤" } ${ schema . maximum } `
77
+ }
78
+ if ( schema . multipleOf !== undefined ) {
79
+ returnObj . constrain = `(multiple\u00a0of\u00a0${ schema . multipleOf } )`
80
+ }
81
+ }
82
+ else if ( schema . type === "string" ) {
83
+ if ( schema . minLength !== undefined && schema . maxLength !== undefined ) {
84
+ returnObj . constrain = `(${ schema . minLength } \u00a0to\u00a0${ schema . maxLength } \u00a0chars)` ;
85
+ }
86
+ else if ( schema . minLength !== undefined && schema . maxLength === undefined ) {
87
+ returnObj . constrain = `(min:${ schema . minLength } \u00a0chars)` ;
88
+ }
89
+ else if ( schema . minLength === undefined && schema . maxLength !== undefined ) {
90
+ returnObj . constrain = `(max:${ schema . maxLength } \u00a0chars)` ;
91
+ }
92
+ }
93
+
94
+ if ( overrideAttributes ) {
95
+ if ( overrideAttributes . readOnly ) {
96
+ returnObj . readOnly = '🆁\u00a0' ;
97
+ }
98
+ if ( overrideAttributes . writeOnly ) {
99
+ returnObj . writeOnly = '🆆\u00a0' ;
100
+ }
101
+ if ( overrideAttributes . deprecated ) {
102
+ returnObj . deprecated = '❌\u00a0' ;
103
+ }
104
+ }
105
+
106
+ // ${returnObj.readOnly}${returnObj.writeOnly}${returnObj.deprecated}\u00a0
107
+ let html = `${ returnObj . type } ` ;
108
+ if ( returnObj . allowedValues ) {
109
+ html = html + `:(${ returnObj . allowedValues } )` ;
110
+ }
111
+ if ( returnObj . readOnly ) {
112
+ html = html + `\u00a0🆁` ;
113
+ }
114
+ if ( returnObj . writeOnly ) {
115
+ html = html + `\u00a0🆆` ;
116
+ }
117
+ if ( returnObj . deprecated ) {
118
+ html = html + `\u00a0❌` ;
119
+ }
120
+
121
+ if ( returnObj . constrain ) {
122
+ html = html + `\u00a0${ returnObj . constrain } ` ;
123
+ }
124
+ if ( returnObj . format ) {
125
+ html = html + `\u00a0${ returnObj . format } ` ;
126
+ }
127
+ if ( returnObj . pattern ) {
128
+ html = html + `\u00a0${ returnObj . pattern } ` ;
129
+ }
130
+ returnObj . html = html ;
131
+ return returnObj ;
132
+ }
133
+
26
134
/* Generates an HTML string containing type and constraint info */
27
- function getTypeInfo ( schema , overrideAttributes = null , inSingleLine = true ) {
135
+ function getTypeInfo ( schema , overrideAttributes = null ) {
28
136
let html = "" ;
29
137
if ( schema . type === "circular" ) {
30
138
return "circular-ref" ;
@@ -90,64 +198,63 @@ function getTypeInfo(schema, overrideAttributes=null, inSingleLine=true){
90
198
}
91
199
}
92
200
93
-
94
- let lineBreak = inSingleLine ?"" :"<br/>" ;
95
201
if ( schema . format ) {
96
- html = html + `${ lineBreak } \u00a0(${ schema . format } )` ;
202
+ html = html + `\u00a0(${ schema . format } )` ;
97
203
}
98
204
if ( schema . pattern && ! schema . enum ) {
99
- html = html + `${ lineBreak } \u00a0(${ schema . pattern } )` ;
205
+ html = html + `\u00a0(${ schema . pattern } )` ;
100
206
}
101
207
return html ;
102
208
}
103
209
104
210
105
211
/* For changing JSON-Schema to a Object Model that can be represnted in a tree-view */
106
212
function schemaToModel ( schema , obj ) {
107
- if ( schema == null ) {
108
- return ;
109
- }
110
- if ( schema . type === "object" || schema . properties ) {
111
- if ( schema . description ) {
112
- obj [ ":description" ] = schema . description ;
113
- }
114
- for ( let key in schema . properties ) {
115
- obj [ key ] = schemaToModel ( schema . properties [ key ] , { } ) ;
116
- }
213
+ if ( schema == null ) {
214
+ return ;
215
+ }
216
+ if ( schema . type === "object" || schema . properties ) {
217
+ if ( schema . description ) {
218
+ obj [ ":description" ] = schema . description ;
117
219
}
118
- else if ( schema . type === "array" || schema . items ) {
119
- //let temp = Object.assign({}, schema.items );
120
- obj = [ schemaToModel ( schema . items , { } ) ]
220
+ for ( let key in schema . properties ) {
221
+ obj [ key ] = schemaToModel ( schema . properties [ key ] , { } ) ;
121
222
}
122
- else if ( schema . allOf ) {
123
- if ( schema . allOf . length === 1 ) {
124
- if ( ! schema . allOf [ 0 ] ) {
125
- return `string~|~${ schema . description ?schema . description :'' } ` ;
126
- }
127
- else {
128
- let overrideAttrib = {
129
- "readOnly" :schema . readOnly ,
130
- "writeOnly" :schema . writeOnly ,
131
- "deprecated" :schema . deprecated
132
- } ;
133
- return `${ getTypeInfo ( schema . allOf [ 0 ] , overrideAttrib ) } ~|~${ schema . description ?schema . description :'' } `
134
- }
135
- }
223
+ }
224
+ else if ( schema . type === "array" || schema . items ) {
225
+ //let temp = Object.assign({}, schema.items );
226
+ obj = [ schemaToModel ( schema . items , { } ) ]
227
+ }
228
+ else if ( schema . allOf ) {
229
+ if ( schema . allOf . length === 1 ) {
230
+ if ( ! schema . allOf [ 0 ] ) {
231
+ return `string~|~${ schema . description ?schema . description :'' } ` ;
232
+ }
233
+ else {
234
+ let overrideAttrib = {
235
+ "readOnly" :schema . readOnly ,
236
+ "writeOnly" :schema . writeOnly ,
237
+ "deprecated" :schema . deprecated
238
+ } ;
136
239
137
- // If allOf is an array of multiple elements, then they are the keys of an object
138
- let objWithAllProps = { } ;
139
- schema . allOf . map ( function ( v ) {
140
- if ( v && v . properties ) {
141
- let partialObj = schemaToModel ( v , { } ) ;
142
- Object . assign ( objWithAllProps , partialObj ) ;
143
- }
144
- } ) ;
145
- obj = objWithAllProps ;
146
- }
147
- else {
148
- return `${ getTypeInfo ( schema ) } ~|~${ schema . description ?schema . description :'' } ` ;
240
+ return `${ getParamTypeInfo ( schema . allOf [ 0 ] , overrideAttrib ) . html } ~|~${ schema . description ?schema . description :'' } `
241
+ }
149
242
}
150
- return obj ;
243
+
244
+ // If allOf is an array of multiple elements, then they are the keys of an object
245
+ let objWithAllProps = { } ;
246
+ schema . allOf . map ( function ( v ) {
247
+ if ( v && v . properties ) {
248
+ let partialObj = schemaToModel ( v , { } ) ;
249
+ Object . assign ( objWithAllProps , partialObj ) ;
250
+ }
251
+ } ) ;
252
+ obj = objWithAllProps ;
253
+ }
254
+ else {
255
+ return `${ getParamTypeInfo ( schema ) . html } ~|~${ schema . description ?schema . description :'' } ` ;
256
+ }
257
+ return obj ;
151
258
}
152
259
153
260
@@ -428,4 +535,4 @@ function removeCircularReferences(level=0) {
428
535
} ;
429
536
430
537
431
- export { debounce , schemaToModel , schemaToObj , schemaToElTree , generateExample , getTypeInfo , getBaseUrlFromUrl , removeCircularReferences }
538
+ export { debounce , schemaToModel , schemaToObj , schemaToElTree , generateExample , getTypeInfo , getParamTypeInfo , getBaseUrlFromUrl , removeCircularReferences }
0 commit comments