Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inheritance Wiki #832

Open
alb3ric opened this issue Dec 5, 2018 · 5 comments
Open

Inheritance Wiki #832

alb3ric opened this issue Dec 5, 2018 · 5 comments

Comments

@alb3ric
Copy link
Contributor

alb3ric commented Dec 5, 2018

Hello,

I'm trying to generate a schema with inheritance.
I try the sample code in the wiki (Animal, Dog) but the schema generated is different from the wiki (9.12.7).
I get the result below. Nno oneOf but mappings instead. Why?

{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Container",
"type": "object",
"additionalProperties": false,
"properties": {
"Animal": {
"$ref": "#/definitions/Animal"
}
},
"definitions": {
"Animal": {
"type": "object",
"discriminator": {
"propertyName": "discriminator",
"mapping": {
"Dog": "#/definitions/Dog"
}
},
"additionalProperties": false,
"required": [
"discriminator"
],
"properties": {
"discriminator": {
"type": "string"
},
"Foo": {
"type": "string"
}
}
},
"Dog": {
"allOf": [
{
"$ref": "#/definitions/Animal"
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"Bar": {
"type": "string"
}
}
}
]
}

Thanks in advance for your help.

Regards

alb3ric

@thebestnom
Copy link
Contributor

Im pretty sure thats the spec, no? Have you tried codegen it back to see what would it generate to?

@RicoSuter
Copy link
Owner

This is as expected: Swagger uses all of with the first element the base schema and the second the schema itself

@alb3ric
Copy link
Contributor Author

alb3ric commented Dec 6, 2018

Hello,

Ok, thanks for your answers.
I had in my sample a class called "Cat" extending Animal.
What I would have like as a result is this (see below). Is this against the specs?

{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Container",
"type": "object",
"additionalProperties": false,
"properties": {
"Animal": {
"oneOf": [
{
"$ref": "#/definitions/Dog"
},
{
"$ref": "#/definitions/Cat"
}
]
}
},
"definitions": {
"Animal": {
"type": "object",
"discriminator": {
"propertyName": "discriminator",
"mapping": {
"Dog": "#/definitions/Dog",
"Cat": "#/definitions/Cat"
}
},
"x-abstract": true,
"additionalProperties": false,
"required": [
"discriminator"
],
"properties": {
"Foo": {
"type": [
"null",
"string"
]
},
"discriminator": {
"type": "string"
}
}
},
"Dog": {
"allOf": [
{
"$ref": "#/definitions/Animal"
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"Ouaf": {
"type": [
"null",
"string"
]
}
}
}
]
},
"Cat": {
"allOf": [
{
"$ref": "#/definitions/Animal"
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"Miaou": {
"type": [
"null",
"string"
]
}
}
}
]
}
}
}

@RicoSuter
Copy link
Owner

RicoSuter commented Dec 6, 2018

BTW: This only works for swagger/openapi. For json schema validation you’d indeed need oneof inheritance - there’s an open issue for that: #13

@alb3ric
Copy link
Contributor Author

alb3ric commented Dec 6, 2018

Ok, I'm in a json schema case.
I'll have a look at the open issue

Thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants