Open JoostvdB94 opened 3 years ago
Another error must have occured. I stripped down the spec to everything but the schema's and it worked fine.
Unfortunately I cannot (yet) share the complete spec as it contains classified information.
Closing it for now as I assume the problem is elsewhere, and cannot be identified without the spec itself.
I managed to reproduce the issue using the following configuration:
openapi: '3.0.2'
info:
title: API Title
version: '1.0'
servers:
- url: https://api.server.test/v1
paths:
/test:
get:
responses:
'200':
description: OK
components:
schemas:
Vehicle:
type: object
PassengerVehicle:
allOf:
- $ref: "#/components/schemas/Vehicle"
- type: object
required:
- numberOfSeats
properties:
numberOfSeats:
type: integer
discriminator:
propertyName: numberOfSeats
mapping:
"1": "#/components/schemas/Bike"
"2": "#/components/schemas/SportsCar"
"3": "#/components/schemas/Car"
"5": "#/components/schemas/Car"
"6": "#/components/schemas/MiniVan"
"10": "#/components/schemas/Bus"
"18": "#/components/schemas/Bus"
"20": "#/components/schemas/Bus"
Bus:
allOf:
- $ref: "#/components/schemas/PassengerVehicle"
- type: object
Car:
allOf:
- $ref: "#/components/schemas/PassengerVehicle"
- type: object
SportsCar:
allOf:
- $ref: "#/components/schemas/PassengerVehicle"
- type: object
MiniVan:
allOf:
- $ref: "#/components/schemas/PassengerVehicle"
- type: object
Bike:
allOf:
- $ref: "#/components/schemas/PassengerVehicle"
- type: object
When I use the sample spec above, the result is the error posted in my first message. If it is altered to only use a single mapping entry per type as illustrated in the following snippet, the error dissapears.
openapi: '3.0.2'
info:
title: API Title
version: '1.0'
servers:
- url: https://api.server.test/v1
paths:
/test:
get:
responses:
'200':
description: OK
components:
schemas:
Vehicle:
type: object
PassengerVehicle:
allOf:
- $ref: "#/components/schemas/Vehicle"
- type: object
required:
- numberOfSeats
properties:
numberOfSeats:
type: integer
discriminator:
propertyName: numberOfSeats
mapping:
"1": "#/components/schemas/Bike"
"2": "#/components/schemas/SportsCar"
"3": "#/components/schemas/Car"
"6": "#/components/schemas/MiniVan"
"10": "#/components/schemas/Bus"
Bus:
allOf:
- $ref: "#/components/schemas/PassengerVehicle"
- type: object
Car:
allOf:
- $ref: "#/components/schemas/PassengerVehicle"
- type: object
SportsCar:
allOf:
- $ref: "#/components/schemas/PassengerVehicle"
- type: object
MiniVan:
allOf:
- $ref: "#/components/schemas/PassengerVehicle"
- type: object
Bike:
allOf:
- $ref: "#/components/schemas/PassengerVehicle"
- type: object
Also, when the allOf-reference in the different PassengerVehicle's are changed to for instance Vehicle
instead of PassengerVehicle
, the code generation works as expected.
Any ideas on how to fix this?
Same Problem here. Any news on it?
@RicoSuter Do you perhaps have any idea where this issue may originate? If so, i'm happy to investigate further and provide a fix
Looking at the stacktrace, this may also be an issue in NJsonSchema (JsonSchema.CodeGeneration.Models.ClassTemplateModelBase.get_DerivedClasses())
Today when I was trying to generate a C# client using NSwagStudio I came across the following error:
After a lot of attempts I found that the following snippet was causing an issue:
after I removed duplicatie values in the mapping, the generation succeeded without errors. (snippet below)
I do not remember reading that duplicate values cannot exist in the OAS3 specification. That's why I think it is a bug.