@@ -111,8 +111,24 @@ export function getSampleValueByType(schemaObj) {
111
111
return schemaObj . $ref ;
112
112
}
113
113
const typeValue = Array . isArray ( schemaObj . type ) ? schemaObj . type [ 0 ] : schemaObj . type ;
114
- if ( typeValue . match ( / ^ i n t e g e r / g) ) { return 0 ; }
115
- if ( typeValue . match ( / ^ n u m b e r / g) ) { return 0.5 ; }
114
+
115
+ if ( typeValue . match ( / ^ i n t e g e r | ^ n u m b e r / g) ) {
116
+ const multipleOf = Number . isNaN ( Number ( schemaObj . multipleOf ) ) ? undefined : Number ( schemaObj . multipleOf ) ;
117
+ const maximum = Number . isNaN ( Number ( schemaObj . maximum ) ) ? undefined : Number ( schemaObj . maximum ) ;
118
+ const minimumPossibleVal = Number . isNaN ( Number ( schemaObj . minimum ) )
119
+ ? Number . isNaN ( Number ( schemaObj . exclusiveMinimum ) )
120
+ ? maximum || 0
121
+ : Number ( schemaObj . exclusiveMinimum ) + ( typeValue . startsWith ( 'integer' ) ? 1 : 0.001 )
122
+ : Number ( schemaObj . minimum ) ;
123
+ const finalVal = multipleOf
124
+ ? multipleOf >= minimumPossibleVal
125
+ ? multipleOf
126
+ : minimumPossibleVal % multipleOf === 0
127
+ ? minimumPossibleVal
128
+ : Math . ceil ( minimumPossibleVal / multipleOf ) * multipleOf
129
+ : minimumPossibleVal ;
130
+ return finalVal ;
131
+ }
116
132
if ( typeValue . match ( / ^ b o o l e a n / g) ) { return false ; }
117
133
if ( typeValue . match ( / ^ n u l l / g) ) { return null ; }
118
134
if ( typeValue . match ( / ^ s t r i n g / g) ) {
@@ -145,8 +161,10 @@ export function getSampleValueByType(schemaObj) {
145
161
return schemaObj . format ;
146
162
}
147
163
} else {
148
- // TODO: check for min and max length
149
- return 'string' ;
164
+ const minLength = Number . isNaN ( schemaObj . minLength ) ? undefined : Number ( schemaObj . minLength ) ;
165
+ const maxLength = Number . isNaN ( schemaObj . maxLength ) ? undefined : Number ( schemaObj . maxLength ) ;
166
+ const finalLength = minLength || ( maxLength > 6 ? 6 : maxLength || undefined ) ;
167
+ return finalLength ? 'A' . repeat ( finalLength ) : 'string' ;
150
168
}
151
169
}
152
170
// If type cannot be determined
@@ -227,17 +245,18 @@ function addPropertyExampleToObjectExamples(example, obj, propertyKey) {
227
245
function mergePropertyExamples ( obj , propertyName , propExamples ) {
228
246
// Create an example for each variant of the propertyExample, merging them with the current (parent) example
229
247
let i = 0 ;
248
+ const maxCombinations = 10 ;
230
249
const mergedObj = { } ;
231
250
for ( const exampleKey in obj ) {
232
251
for ( const propExampleKey in propExamples ) {
233
252
mergedObj [ `example-${ i } ` ] = { ...obj [ exampleKey ] } ;
234
253
mergedObj [ `example-${ i } ` ] [ propertyName ] = propExamples [ propExampleKey ] ;
235
254
i ++ ;
236
- if ( i >= 10 ) {
255
+ if ( i >= maxCombinations ) {
237
256
break ;
238
257
}
239
258
}
240
- if ( i >= 10 ) {
259
+ if ( i >= maxCombinations ) {
241
260
break ;
242
261
}
243
262
}
0 commit comments