@@ -7,10 +7,6 @@ import type { Route } from './route';
77import type { Schema } from './ir' ;
88import { Block } from 'comment-parser' ;
99
10- type ExtendedOpenApiSchema = OpenAPIV3 . SchemaObject & {
11- arrayExample ?: string ;
12- } ;
13-
1410function schemaToOpenAPI (
1511 schema : Schema ,
1612) : OpenAPIV3 . SchemaObject | OpenAPIV3 . ReferenceObject | undefined {
@@ -55,14 +51,19 @@ function schemaToOpenAPI(
5551 return undefined ;
5652 }
5753
58- const { arrayExample, minItems, maxItems, ...rest } = defaultOpenAPIObject ;
54+ const { example, minItems, maxItems, ...rest } = defaultOpenAPIObject ;
55+ const isArrayExample = example && Array . isArray ( example ) ;
5956
6057 return {
6158 type : 'array' ,
6259 ...( minItems ? { minItems } : { } ) ,
6360 ...( 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+ } ,
6667 } ;
6768 case 'object' :
6869 return {
@@ -186,7 +187,7 @@ function schemaToOpenAPI(
186187 }
187188 } ;
188189
189- function buildDefaultOpenAPIObject ( schema : Schema ) : ExtendedOpenApiSchema {
190+ function buildDefaultOpenAPIObject ( schema : Schema ) : OpenAPIV3 . SchemaObject {
190191 const emptyBlock : Block = { description : '' , tags : [ ] , source : [ ] , problems : [ ] } ;
191192 const jsdoc = parseCommentBlock ( schema . comment ?? emptyBlock ) ;
192193
@@ -209,7 +210,6 @@ function schemaToOpenAPI(
209210 const writeOnly = jsdoc ?. tags ?. writeOnly ?? schema . writeOnly ;
210211 const format = jsdoc ?. tags ?. format ?? schema . format ?? schema . format ;
211212 const title = jsdoc ?. tags ?. title ?? schema . title ;
212- const arrayExample = jsdoc ?. tags ?. arrayExample ?? '' ;
213213
214214 const deprecated =
215215 Object . keys ( jsdoc ?. tags || { } ) . includes ( 'deprecated' ) || ! ! schema . deprecated ;
@@ -237,7 +237,6 @@ function schemaToOpenAPI(
237237 ...( writeOnly ? { writeOnly : true } : { } ) ,
238238 ...( format ? { format } : { } ) ,
239239 ...( title ? { title } : { } ) ,
240- ...( arrayExample ? { arrayExample } : { } ) ,
241240 } ;
242241
243242 return defaultOpenAPIObject ;
0 commit comments