Behavior of the allOf and discriminator #3025
-
Hello! I have a few pieces of questions related to a combination of I have following OpenAPI spec openapi: 3.0.3
info:
title: 'Example'
version: 0.1.0
servers:
- url: 'http://example.com'
paths:
‘/users’:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/User"
components:
schemas:
User:
type: object
properties:
$type:
type: string
shared_property:
type: string
discriminator:
propertyName: "$type"
UserA:
allOf: [
$ref: "#/components/schemas/User"
]
type: object
properties:
foo:
type: string
UserB:
allOf: [
$ref: "#/components/schemas/User"
]
type: object
properties:
bar:
type: string In case of GET request to
I have doubts because I use this spec to generate python client using openapi-generator. And in generated …
def discriminator():
lazy_import()
val = {
'UserA': UserA,
'UserB': UserB,
}
… Seems like It may be fixed in 2 ways
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
allOf makes it an inheritance. Superclass should neither know of nor include its subclasses. The specification you've attached says your endpoint returns only a list of responses:
default:
content:
application/json:
schema:
type: array
items:
oneOf:
- $ref: '#/components/schemas/UserA'
- $ref: '#/components/schemas/UserB'
- $ref: '#/components/schemas/User' Not sure about discriminator, but you can try adding |
Beta Was this translation helpful? Give feedback.
-
Answer accepted, closing. |
Beta Was this translation helpful? Give feedback.
allOf makes it an inheritance. Superclass should neither know of nor include its subclasses.
The specification you've attached says your endpoint returns only a list of
User
. SinceadditionalProperties
is true by default, it may return objects that happen to validate againstUserA
and/orUserB
but that's not declared explicitly.Not sure about discriminator, but you can try adding
additionalProperties: false
to Use…