@@ -7,10 +7,6 @@ import type { Route } from './route';
7
7
import type { Schema } from './ir' ;
8
8
import { Block } from 'comment-parser' ;
9
9
10
- type ExtendedOpenApiSchema = OpenAPIV3 . SchemaObject & {
11
- arrayExample ?: string ;
12
- } ;
13
-
14
10
function schemaToOpenAPI (
15
11
schema : Schema ,
16
12
) : OpenAPIV3 . SchemaObject | OpenAPIV3 . ReferenceObject | undefined {
@@ -55,14 +51,19 @@ function schemaToOpenAPI(
55
51
return undefined ;
56
52
}
57
53
58
- const { arrayExample, minItems, maxItems, ...rest } = defaultOpenAPIObject ;
54
+ const { example, minItems, maxItems, ...rest } = defaultOpenAPIObject ;
55
+ const isArrayExample = example && Array . isArray ( example ) ;
59
56
60
57
return {
61
58
type : 'array' ,
62
59
...( minItems ? { minItems } : { } ) ,
63
60
...( maxItems ? { maxItems } : { } ) ,
64
- ...( arrayExample ? { example : JSON . parse ( arrayExample ) } : { } ) , // Add example to array if it exists
65
- items : { ...innerSchema , ...rest } ,
61
+ ...( isArrayExample ? { example } : { } ) ,
62
+ items : {
63
+ ...innerSchema ,
64
+ ...rest ,
65
+ ...( ! isArrayExample && example ? { example } : { } ) ,
66
+ } ,
66
67
} ;
67
68
case 'object' :
68
69
return {
@@ -186,7 +187,7 @@ function schemaToOpenAPI(
186
187
}
187
188
} ;
188
189
189
- function buildDefaultOpenAPIObject ( schema : Schema ) : ExtendedOpenApiSchema {
190
+ function buildDefaultOpenAPIObject ( schema : Schema ) : OpenAPIV3 . SchemaObject {
190
191
const emptyBlock : Block = { description : '' , tags : [ ] , source : [ ] , problems : [ ] } ;
191
192
const jsdoc = parseCommentBlock ( schema . comment ?? emptyBlock ) ;
192
193
@@ -209,7 +210,6 @@ function schemaToOpenAPI(
209
210
const writeOnly = jsdoc ?. tags ?. writeOnly ?? schema . writeOnly ;
210
211
const format = jsdoc ?. tags ?. format ?? schema . format ?? schema . format ;
211
212
const title = jsdoc ?. tags ?. title ?? schema . title ;
212
- const arrayExample = jsdoc ?. tags ?. arrayExample ?? '' ;
213
213
214
214
const deprecated =
215
215
Object . keys ( jsdoc ?. tags || { } ) . includes ( 'deprecated' ) || ! ! schema . deprecated ;
@@ -237,7 +237,6 @@ function schemaToOpenAPI(
237
237
...( writeOnly ? { writeOnly : true } : { } ) ,
238
238
...( format ? { format } : { } ) ,
239
239
...( title ? { title } : { } ) ,
240
- ...( arrayExample ? { arrayExample } : { } ) ,
241
240
} ;
242
241
243
242
return defaultOpenAPIObject ;
0 commit comments