File tree Expand file tree Collapse file tree 2 files changed +57
-2
lines changed Expand file tree Collapse file tree 2 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -562,5 +562,59 @@ describe('Models', () => {
562
562
`"testAttr: <object> (Refed description)"` ,
563
563
) ;
564
564
} ) ;
565
+
566
+ test ( 'should correct get title from in oneOf ->const' , ( ) => {
567
+ const spec = parseYaml ( outdent `
568
+ openapi: 3.0.0
569
+ paths:
570
+ /test:
571
+ get:
572
+ operationId: test
573
+ responses:
574
+ '200':
575
+ content:
576
+ application/json:
577
+ schema:
578
+ type: object
579
+ properties:
580
+ data:
581
+ type: object
582
+ properties:
583
+ response_code:
584
+ type: integer
585
+ description: A numeric response code
586
+ oneOf:
587
+ - const: 0
588
+ description: >
589
+ Description for const 0
590
+ - const: 1
591
+ description: >
592
+ Description for const 1
593
+ - const: 2
594
+ description: >
595
+ Description for const 2
596
+ ` ) as any ;
597
+
598
+ parser = new OpenAPIParser ( spec , undefined , opts ) ;
599
+ const name = 'application/json' ;
600
+ const mediaType = new MediaTypeModel (
601
+ parser ,
602
+ name ,
603
+ true ,
604
+ spec . paths [ '/test' ] . get . responses [ '200' ] . content [ name ] ,
605
+ opts ,
606
+ ) ;
607
+
608
+ expect ( printSchema ( mediaType ?. schema as any ) ) . toMatchInlineSnapshot ( `
609
+ "data:
610
+ response_code: oneOf
611
+ 0 -> <integer> (Description for const 0
612
+ )
613
+ 1 -> <integer> (Description for const 1
614
+ )
615
+ 2 -> <integer> (Description for const 2
616
+ )"
617
+ ` ) ;
618
+ } ) ;
565
619
} ) ;
566
620
} ) ;
Original file line number Diff line number Diff line change @@ -243,8 +243,9 @@ export class SchemaModel {
243
243
const title =
244
244
isNamedDefinition ( variant . $ref ) && ! merged . title
245
245
? JsonPointer . baseName ( variant . $ref )
246
- : `${ merged . title || '' } ${ ( merged . const && JSON . stringify ( merged . const ) ) || '' } ` ;
247
-
246
+ : `${ merged . title || '' } ${
247
+ ( typeof merged . const !== 'undefined' && JSON . stringify ( merged . const ) ) || ''
248
+ } `;
248
249
const schema = new SchemaModel (
249
250
parser ,
250
251
// merge base schema into each of oneOf's subschemas
You can’t perform that action at this time.
0 commit comments