raml-java-parser icon indicating copy to clipboard operation
raml-java-parser copied to clipboard

method Resource org.raml.model.Resource.getResource(String path) does not work with multiple resources named with the same prefix

Open jeromecupif opened this issue 9 years ago • 0 comments

aRamlInstance.getResource("/orderDomain/orders/{orderId}") => null

method Resource org.raml.model.Resource.getResource(String path) does not work with multiple resources named with the same prefix example : path ="/orderDomain/orders" : OK path ="/orderDomain/orders/{orderId}" : KO path ="/orderDomain/orders/services" : KO

the code below for the resource "/orderDomain/orders" and the path "/orderDomain/orders/{orderId}" enters the "if(path.charAt(resource.getRelativeUri().length()) == 47)" block and the next line return null because the

path.substring(resource.getRelativeUri().length())

expression is worth "{orderId}". The resource "/orderDomain/orders/{orderId}" in the resource /orderDomain is never reached because of the null return and the Raml.getResource returns null.

public Resource getResource(String path) {
    Iterator i$ = this.resources.values().iterator();

    while(i$.hasNext()) {
        Resource resource = (Resource)i$.next();
        if(path.startsWith(resource.getRelativeUri())) {
            if(path.length() == resource.getRelativeUri().length()) {
                return resource;
            }

            if(**path.charAt(resource.getRelativeUri().length()) == 47**) {
                return **resource.getResource(path.substring(resource.getRelativeUri().length()))**;
            }
        }
    }

    return null;
}

Aha! Link: https://mulesoft-roadmap.aha.io/features/APIRAML-126

jeromecupif avatar Aug 18 '16 11:08 jeromecupif