Comments (3)
@johanhenriksson did you find a workaround for this issue?
The only thing I've found it to define a kind of type alias
to use in oneOf
schema, e.g.
StringForDiscriminator:
allOf:
- $ref: '#/components/types/String'
- type: object
properties:
kind:
type: string
In that case we have 2 objects generated, one to be used in the case with discriminator, and another one without. But it looks a bit ugly, tbh.
Another solution is to just define a map and put data there
additionalProperties:
type: string
from ogen.
So having following schema
openapi: 3.0.3
info:
title: Discriminator example
description: Example
version: 1.0.0
paths:
/example:
get:
responses:
200:
description: OK
content:
"application/json":
schema:
$ref: '#/components/schemas/Response'
components:
schemas:
Alpha:
type: object
required:
- kind
- variant
- data
properties:
kind:
type: string
variant:
type: string
data:
type: string
Beta:
type: object
required:
- kind
- variant
- value
properties:
kind:
type: string
variant:
type: string
value:
type: string
SumAuto:
oneOf:
- $ref: '#/components/schemas/Alpha'
- $ref: '#/components/schemas/Beta'
SumFirst:
discriminator:
propertyName: kind
mapping:
alpha: '#/components/schemas/Alpha'
beta: '#/components/schemas/Beta'
oneOf:
- $ref: '#/components/schemas/Alpha'
- $ref: '#/components/schemas/Beta'
SumSecond:
discriminator:
propertyName: variant
mapping:
a: '#/components/schemas/Alpha'
b: '#/components/schemas/Beta'
oneOf:
- $ref: '#/components/schemas/Alpha'
- $ref: '#/components/schemas/Beta'
Response:
type: object
required:
- Auto
- First
- Second
- Alpha
- Beta
properties:
Auto:
$ref: '#/components/schemas/SumAuto'
First:
$ref: '#/components/schemas/SumFirst'
Second:
$ref: '#/components/schemas/SumSecond'
Alpha:
$ref: '#/components/schemas/Alpha'
Beta:
$ref: '#/components/schemas/Beta'
Discriminator properties are removed from Alpha
and Beta
, but should not.
@tdakkota please take a look.
from ogen.
@vkuptcov I have not found a good workaround to this, no. We managed to do without it, but having the discriminator field on the generated types would make life easier.
from ogen.
Related Issues (20)
- [Misnamed Schema Object]: OpenAPI schema object name incorrectly being generated/used HOT 7
- External references don't work HOT 2
- Proposal: Allow grouping operations into separate handlers
- Custom types HOT 1
- Multiple response types are not generated for the same field
- Incorrect generation of free-form objects HOT 3
- extensions: support providing extensions in ogen.Spec, that can be marshalled to JSON
- Discriminator in oneOf unions appears twice in response HOT 6
- [Bug]: [oneOf decode failed]
- [SUBJECT]: [DESCRIPTION]
- Incorrect handling of empty optional UUID array header
- [cli/config]: Return no-client/no-server to the cli
- Should support custom metrics prefix
- perf: zap library leaking into binaries HOT 1
- bug: trialing dash breaks routing
- Encode/Decode: Unmarshal creates error, while marshal works fine HOT 2
- Discriminator Inference Regression: Specification working with 1.1.1 no longer works in 1.2.x
- Support getting underlying vale from oneOf type
- length validation of bytes fields incorrectly converts to utf-8 string
- oneOf: incorrectly typed as map[string]jx.Raw in 1.2.0, 1.2.1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ogen.