mulesoft-labs / raml-java-tools

Apache License 2.0
19 stars 20 forks source link

Looks like verification of non mandatory object properties #51

Open moisesventura opened 4 years ago

moisesventura commented 4 years ago

The current buildLooksLike code verifies the document to deserialize contains all the properties (required and non-required) from the RAML object declaration. This causes the object identification (and thereby the deserialization) to fail if any of the non-required properties is missing from the response document.

By adding the following code only the mandatory properties are verified:

List<TypeDeclaration> mandatoryProperties = otd.properties().stream().filter(propertyTypeDeclaration -> propertyTypeDeclaration.required())
                    .collect(Collectors.toList());

This results into code like the following (with no optional attributes in the containsAll):

    private boolean looksLikeMortgageAccount(Map<String, Object> map) {
      return map.keySet().containsAll(Arrays.asList("accountId","type")) && map.get("type").equals("MORTGAGE");
    }
moisesventura commented 4 years ago

Pull request https://github.com/mulesoft-labs/raml-java-tools/pull/49