raml-java-parser
raml-java-parser copied to clipboard
Cannot specialize data types property type by inheritance
Affects: 1.0.0
Issue
I'd expect to be able to specialize an extended data type's property into a narrower type but can't manage to do that.
Spec pointer
A sub-type can override properties of its parent type with the following restrictions: 1) a required property in the parent type cannot be changed to optional in the sub-type, and 2) the type declaration of a defined property in the parent type can only be changed to a narrower type (a specialization of the parent type) in the sub-type.
How to reproduce
RAML file
# %RAML 1.0
title: My API title types: Pet: properties: name: string cost: number Dog: type: Pet properties: cost: integer ```
#### Java file
``` java package com.restlet.definitions.raml10.reader;
import com.fasterxml.jackson.databind.ObjectMapper; import org.raml.v2.api.RamlModelBuilder; import org.raml.v2.api.RamlModelResult; import org.raml.v2.api.model.v10.api.Api; import org.raml.v2.api.model.v10.datamodel.NumberTypeDeclaration; import org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration;
import static org.junit.Assert.assertEquals;
public class Test {
@org.junit.Testpublic void test() throws Exception { String savedRamlLocation = Test.class.getResource("fileName").toString(); RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(savedRamlLocation); if (ramlModelResult.hasErrors()) { throw new RuntimeException("Parsing of RAML 1.0 file failed with following errors:\n" + new ObjectMapper().writeValueAsString(ramlModelResult.getValidationResults())); } Api savedRaml = ramlModelResult.getApiV10(); ObjectTypeDeclaration dog = (ObjectTypeDeclaration) savedRaml.types().get(1); NumberTypeDeclaration cost = (NumberTypeDeclaration) dog.properties().get(1); assertEquals("integer", cost.type());}
} ```
Aha! Link: https://mulesoft-roadmap.aha.io/features/APIRAML-124