@@ -76,6 +76,7 @@ export class DefinitionGenerator {
7676 // loop through http events
7777 for ( const httpEvent of this . getHttpEvents ( funcConfig . events ) ) {
7878 const httpEventConfig = httpEvent . http ;
79+
7980 if ( httpEventConfig . documentation ) {
8081 const documentationConfig = httpEventConfig . documentation ;
8182 // Build OpenAPI path configuration structure for each method
@@ -91,6 +92,7 @@ export class DefinitionGenerator {
9192 } ,
9293 } ,
9394 } ;
95+
9496 // merge path configuration into main configuration
9597 merge ( this . definition . paths , pathConfig ) ;
9698 }
@@ -150,7 +152,7 @@ export class DefinitionGenerator {
150152 if ( type === 'path' ) {
151153 parameterConfig . required = true ;
152154 } else if ( type === 'query' ) {
153- parameterConfig . allowEmptyValues = parameter . allowEmptyValue || false ; // OpenAPI default is false
155+ parameterConfig . allowEmptyValue = parameter . allowEmptyValue || false ; // OpenAPI default is false
154156
155157 if ( 'allowReserved' in parameter ) {
156158 parameterConfig . allowReserved = parameter . allowReserved || false ;
@@ -209,12 +211,7 @@ export class DefinitionGenerator {
209211 } ,
210212 } ;
211213
212- // Add examples if any can be found
213- if ( requestModel . examples && Array . isArray ( requestModel . examples ) ) {
214- merge ( reqModelConfig , { examples : clone ( requestModel . examples ) } ) ;
215- } else if ( requestModel . example ) {
216- merge ( reqModelConfig , { example : clone ( requestModel . example ) } ) ;
217- }
214+ this . applyExamples ( requestModel , reqModelConfig ) ;
218215
219216 const reqBodyConfig : { content : object , description ?: string } = {
220217 content : {
@@ -234,6 +231,14 @@ export class DefinitionGenerator {
234231 return requestBodies ;
235232 }
236233
234+ private applyExamples ( target , config ) {
235+ if ( target . examples && Array . isArray ( target . examples ) ) {
236+ merge ( config , { examples : clone ( target . examples ) } ) ;
237+ } else if ( target . example ) {
238+ merge ( config , { example : clone ( target . example ) } ) ;
239+ }
240+ }
241+
237242 /**
238243 * Gets response bodies from documentation config
239244 * @param documentationConfig
@@ -274,21 +279,21 @@ export class DefinitionGenerator {
274279
275280 private getResponseContent ( response ) {
276281 const content = { } ;
282+
277283 for ( const responseKey of Object . keys ( response ) ) {
278- const responseModel = this . config . models . filter (
279- ( model ) => model . name === response [ responseKey ] ,
280- ) . pop ( ) ;
284+ const responseModel = this . config . models . find ( ( model ) =>
285+ model . name === response [ responseKey ] ,
286+ ) ;
287+
281288 if ( responseModel ) {
282289 const resModelConfig = {
283290 schema : {
284291 $ref : `#/components/schemas/${ response [ responseKey ] } ` ,
285292 } ,
286293 } ;
287- if ( responseModel . examples && Array . isArray ( responseModel . examples ) ) {
288- merge ( resModelConfig , { examples : clone ( responseModel . examples ) } ) ;
289- } else if ( responseModel . example ) {
290- merge ( resModelConfig , { example : clone ( responseModel . example ) } ) ;
291- }
294+
295+ this . applyExamples ( responseModel , resModelConfig ) ;
296+
292297 merge ( content , { [ responseKey ] : resModelConfig } ) ;
293298 }
294299 }
0 commit comments