@@ -133,6 +133,25 @@ function schemaToOpenAPI(
133133 }
134134 } ;
135135
136+ /**
137+ * This function will return the field value parsed as the type of the schema. i.e. if the schema is a number, it will return the field as a JS number.
138+ *
139+ * @param schema A schema object
140+ * @param fieldValue The value to parse
141+ * @returns the parsed value
142+ */
143+ const parseField = ( schema : Schema , fieldValue : string ) : any => {
144+ if ( schema . type === 'number' || schema . type === 'integer' ) {
145+ return Number ( fieldValue ) ;
146+ } else if ( schema . type === 'boolean' ) {
147+ return fieldValue === 'true' ;
148+ } else if ( schema . type === 'null' ) {
149+ return null ;
150+ } else {
151+ return fieldValue ;
152+ }
153+ } ;
154+
136155 function buildDefaultOpenAPIObject ( schema : Schema ) : OpenAPIV3 . SchemaObject {
137156 const defaultValue = getTagName ( schema , 'default' ) ;
138157 const example = getTagName ( schema , 'example' ) ;
@@ -157,10 +176,10 @@ function schemaToOpenAPI(
157176 const description = schema . comment ?. description ;
158177
159178 const defaultOpenAPIObject = {
160- ...( defaultValue ? { default : defaultValue } : { } ) ,
179+ ...( defaultValue ? { default : parseField ( schema , defaultValue ) } : { } ) ,
161180 ...( deprecated ? { deprecated : true } : { } ) ,
162181 ...( description ? { description } : { } ) ,
163- ...( example ? { example } : { } ) ,
182+ ...( example ? { example : parseField ( schema , example ) } : { } ) ,
164183 ...( maxLength ? { maxLength : Number ( maxLength ) } : { } ) ,
165184 ...( minLength ? { minLength : Number ( minLength ) } : { } ) ,
166185 ...( pattern ? { pattern } : { } ) ,
0 commit comments