@@ -105,7 +105,8 @@ export function getTypeInfo(parameter, options = { includeNulls: false, enableEx
105
105
106
106
export function getSampleValueByType ( schemaObj , fallbackPropertyName , skipExampleIds ) {
107
107
const example = Array . isArray ( schemaObj . examples ) ? schemaObj . examples [ 0 ] : Object . values ( schemaObj . examples || { } ) [ 0 ] ?. value ?? schemaObj . example ;
108
- if ( skipExampleIds && typeof example === 'string' && fallbackPropertyName . match ( / i d $ / i) ) { return '' ; }
108
+ const propertyName = fallbackPropertyName || 'string' ;
109
+ if ( skipExampleIds && typeof example === 'string' && propertyName . match ( / i d $ / i) ) { return '' ; }
109
110
if ( typeof example !== 'undefined' ) { return example ; }
110
111
111
112
if ( schemaObj . default ) { return schemaObj . default ; }
@@ -142,14 +143,14 @@ export function getSampleValueByType(schemaObj, fallbackPropertyName, skipExampl
142
143
}
143
144
if ( typeValue . match ( / ^ b o o l e a n / g) ) { return false ; }
144
145
if ( typeValue . match ( / ^ n u l l / g) ) { return null ; }
145
- if ( skipExampleIds && typeValue . match ( / ^ s t r i n g / g) && fallbackPropertyName . match ( / i d $ / i) ) { return '' ; }
146
+ if ( skipExampleIds && typeValue . match ( / ^ s t r i n g / g) && propertyName . match ( / i d $ / i) ) { return '' ; }
146
147
if ( typeValue . match ( / ^ s t r i n g / g) ) {
147
148
if ( schemaObj . pattern ) {
148
149
const examplePattern = schemaObj . pattern . replace ( / [ + * ] (? ! [ ^ \] [ ] * [ \] ] ) / g, '{8}' ) . replace ( / \{ \d * , ( \d + ) ? \} / g, '{8}' ) ;
149
150
try {
150
- return new RandExp ( examplePattern ) . gen ( ) || fallbackPropertyName || 'string' ;
151
+ return new RandExp ( examplePattern ) . gen ( ) || propertyName ;
151
152
} catch ( error ) {
152
- return fallbackPropertyName || 'string' ;
153
+ return propertyName ;
153
154
}
154
155
}
155
156
if ( schemaObj . format ) {
@@ -185,7 +186,7 @@ export function getSampleValueByType(schemaObj, fallbackPropertyName, skipExampl
185
186
return schemaObj . format ;
186
187
}
187
188
} else {
188
- return fallbackPropertyName || 'string' ;
189
+ return propertyName ;
189
190
}
190
191
}
191
192
// If type cannot be determined
0 commit comments