Skip to content

Commit 69e91a3

Browse files
committed
fix: add support for discriminator in oneOf schemas and update model imports
1 parent b6b71cd commit 69e91a3

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{{#hasImports}}
2-
{{#imports}}
2+
{{#oneOfModels}}
33
import type { {{{.}}} } from './{{.}}{{importFileExtension}}';
44
import {
55
instanceOf{{{.}}},
66
{{{.}}}FromJSON,
77
{{{.}}}FromJSONTyped,
88
{{{.}}}ToJSON,
99
} from './{{.}}{{importFileExtension}}';
10-
{{/imports}}
10+
{{/oneOfModels}}
1111

1212
{{/hasImports}}
1313
{{>modelOneOfInterfaces}}

modules/openapi-generator/src/test/resources/3_0/typescript-fetch/oneOf.yaml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ paths:
2525
application/json:
2626
schema:
2727
$ref: '#/components/schemas/TestArrayResponse'
28+
/test-discriminator:
29+
get:
30+
operationId: testDiscriminator
31+
responses:
32+
200:
33+
description: OK
34+
content:
35+
application/json:
36+
schema:
37+
$ref: '#/components/schemas/TestDiscriminatorResponse'
2838
components:
2939
schemas:
3040
TestArrayResponse:
@@ -38,6 +48,15 @@ components:
3848
- type: array
3949
items:
4050
type: string
51+
TestDiscriminatorResponse:
52+
discriminator:
53+
propertyName: discriminatorField
54+
mapping:
55+
optionOne: "#/components/schemas/OptionOne"
56+
optionTwo: "#/components/schemas/OptionTwo"
57+
oneOf:
58+
- $ref: "#/components/schemas/OptionOne"
59+
- $ref: "#/components/schemas/OptionTwo"
4160
TestResponse:
4261
oneOf:
4362
- $ref: "#/components/schemas/TestA"
@@ -56,4 +75,22 @@ components:
5675
bar:
5776
type: string
5877
required:
59-
- bar
78+
- bar
79+
OptionOne:
80+
type: object
81+
properties:
82+
discriminatorField:
83+
enum:
84+
- "optionOne"
85+
type: string
86+
required:
87+
- discriminatorField
88+
OptionTwo:
89+
type: object
90+
properties:
91+
discriminatorField:
92+
enum:
93+
- "optionTwo"
94+
type: string
95+
required:
96+
- discriminatorField

0 commit comments

Comments
 (0)