mulesoft-labs / raml-for-jax-rs

This project is all about two way transformation of JAX-RS-annotated Java code to RAML API description and back.
Other
296 stars 181 forks source link

JSON validator becomes confused when two unrelated classes have same discriminatorValue. #424

Open diggernet opened 4 years ago

diggernet commented 4 years ago

Version: 3.0.7 Scenario: Define two unrelated types with discriminators, and subtypes of them which happen to have the same discriminatorValue. Error: [ERROR] Failed to execute goal org.raml.jaxrs:raml-to-jaxrs-maven-plugin:3.0.7:generate (default) on project schema-test: Error generating Java classes from: null: [Error validating JSON. Error: - Missing required field "animalType" [ERROR] - Missing required field "age" [ERROR] - Missing required field "spots" -- C:/path/to/test.raml [line=38, col=14]]

Note that line 38 is the reference for vehicle.json. It is looking for Animal and Cat fields in the Vehicle->Jaguar JSON.

Commenting out the example declarations allows a successful build, with apparently-correct code generated. Only the validation step appears broken.

test.raml: `

%RAML 1.0 Library

types: Response: type: object properties: myPet: type: Animal myCar: type: Vehicle

Animal: type: object discriminator: animalType properties: animalType: string age: integer

Cat: type: Animal discriminatorValue: JAGUAR properties: spots: boolean example: !include examples/animal.json

Vehicle: type: object discriminator: vehicleType properties: vehicleType: string color: string

Jaguar: type: Vehicle discriminatorValue: JAGUAR properties: model: string example: !include examples/vehicle.json `

animal.json: { "animalType": "JAGUAR", "age": 3, "spots": false }

vehicle.json { "vehicleType": "JAGUAR", "color": "red", "model": "XK120" }