private String transformAPIName(final org.raml.model.Resource sourceResourceRoot) { final String extendedName = sourceResourceRoot.getRelativeUri().replaceAll("\\{mediaTypeExtension\\}", " ").trim() .replaceAll("[\\W_]", " "); return WordUtils.capitalize(extendedName).replaceAll("/", " ").replaceAll("[\\W_]", "").trim(); }
public Resource getResource(String path) { for (Resource resource : resources.values()) { if (path.startsWith(resource.getRelativeUri())) { if (path.length() == resource.getRelativeUri().length()) { return resource; } if (path.charAt(resource.getRelativeUri().length()) == '/') { return resource.getResource(path.substring(resource.getRelativeUri().length())); } } } return null; } }
public Resource getResource(String path) { for (Resource resource : resources.values()) { if (path.startsWith(resource.getRelativeUri())) { if (path.length() == resource.getRelativeUri().length()) { return resource; } if (path.charAt(resource.getRelativeUri().length()) == '/') { return resource.getResource(path.substring(resource.getRelativeUri().length())); } } } return null; }
public void resourcePattern(Resource resource) { if (resourcePattern != null) { final String uri = resource.getRelativeUri().replaceAll("\\{[^}/]+\\}", ""); for (final String part : uri.split("/")) { if (part != null && part.length() > 0 && !resourcePattern.matcher(part).matches()) { violation("resource.name.invalid", locator, resourcePattern.pattern()); } } } }
private void populateDefaultUriParameters(Resource resource) { Pattern pattern = Pattern.compile(URI_PATTERN); Matcher matcher = pattern.matcher(resource.getRelativeUri()); while (matcher.find()) { String paramName = matcher.group(1); if (!resource.getUriParameters().containsKey(paramName)) { resource.getUriParameters().put(paramName, new UriParameter(paramName)); } } }
private void populateDefaultUriParameters(Resource resource) { Pattern pattern = Pattern.compile(URI_PATTERN); Matcher matcher = pattern.matcher(resource.getRelativeUri()); while (matcher.find()) { String paramName = matcher.group(1); if (!resource.getUriParameters().containsKey(paramName)) { resource.getUriParameters().put(paramName, new UriParameter(paramName)); } } }
private void assureUriParameterBound(final org.raml.model.Resource source) { for (final String singleUriParam : source.getUriParameters().keySet()) { if (!source.getRelativeUri().contains(singleUriParam)) { throw new IllegalArgumentException( "Could not find matching uri path for resource " + source.getUri() + " for " + "defined uri parameter " + singleUriParam + " (" + source.getUriParameters().get(singleUriParam) + ")"); } } }
/** * Returns a RAML Resource given its complete path. * * @param raml * The RAML in which the Resource is searched for. * @param path * The complete path of the resource. * @return The Resource. */ private static Resource getResourceByCompletePath(Raml raml, String path) { for (Entry<String, Resource> entry : raml.getResources().entrySet()) { if (path.equals(entry.getValue().getParentUri() + entry.getValue().getRelativeUri())) { return entry.getValue(); } } return null; }
/** * Returns a RAML Resource given its complete path. * * @param raml * The RAML in which the Resource is searched for. * @param path * The complete path of the resource. * @return The Resource. */ private static Resource getResourceByCompletePath(Raml raml, String path) { for (Entry<String, Resource> entry : raml.getResources().entrySet()) { if (path.equals(entry.getValue().getParentUri() + entry.getValue().getRelativeUri())) { return entry.getValue(); } } return null; }
/** * Returns a RAML Resource given its complete path. * * @param raml * The RAML in which the Resource is searched for. * @param path * The complete path of the resource. * @return The Resource. */ private static Resource getResourceByCompletePath(Raml raml, String path) { for (Entry<String, Resource> entry : raml.getResources().entrySet()) { if (path.equals(entry.getValue().getParentUri() + entry.getValue().getRelativeUri())) { return entry.getValue(); } } return null; }
/** * Returns a RAML Resource given its complete path. * * @param raml * The RAML in which the Resource is searched for. * @param path * The complete path of the resource. * @return The Resource. */ private static Resource getResourceByCompletePath(Raml raml, String path) { for (Entry<String, Resource> entry : raml.getResources().entrySet()) { if (path.equals(entry.getValue().getParentUri() + entry.getValue().getRelativeUri())) { return entry.getValue(); } } return null; }
private static String resolveMethodPath(final Action source, final List<org.raml.model.Resource> parents) { final org.raml.model.Resource rootParent; if (!parents.isEmpty()) { rootParent = parents.get(0); } else { rootParent = source.getResource(); } return source.getResource().getUri().substring(rootParent.getRelativeUri().length()); }
public static String classPart(Resource resource) { if (resource == null) { return ""; } String name = isNotEmpty(resource.getDisplayName()) ? sanitize(resource.getDisplayName()) : sanitize(resource.getRelativeUri()) .replace(".", ""); return capitalize(name.contains("/") ? substringAfterLast(name, "/") : name); }
public static String buildResourceInterfaceName(final Resource resource) { final String resourceInterfaceName = buildJavaFriendlyName(defaultIfBlank(resource.getDisplayName(), resource.getRelativeUri())); return isBlank(resourceInterfaceName) ? "Root" : resourceInterfaceName; }
/** * Build a suitable Java type-name for a RAML Resource with a suffix. * * @param ramlResource the RAML resource. * @return a corresponding Java type-name. */ public static String buildTypeName(final Resource ramlResource) { if (ramlResource == null) { return null; } final String ramlUri = Strings.nullToEmpty(ramlResource.getParentUri()) + Strings.nullToEmpty(ramlResource.getRelativeUri()); final String resourceInterfaceName = buildName( StringUtils.defaultIfBlank( ramlResource.getDisplayName(), ramlUri)); return StringUtils.isBlank(resourceInterfaceName) ? ROOT_RESOURCE_NAME : resourceInterfaceName; }
/** * <p>buildResourceInterfaceName.</p> * * @param resource a {@link org.raml.model.Resource} object. * @return a {@link java.lang.String} object. */ public static String buildResourceInterfaceName(final Resource resource,Configuration config) { final String resourceInterfaceName = buildJavaFriendlyName(defaultIfBlank(resource.getDisplayName(), resource.getRelativeUri())); //return isBlank(resourceInterfaceName) ? "Root" : resourceInterfaceName.concat("Resource"); return isBlank(resourceInterfaceName) ? "Root" : resourceInterfaceName.concat(config.getInterfaceNameSuffix()); }
@Override public boolean onMappingNodeStart(MappingNode mappingNode, TupleType tupleType) { super.onMappingNodeStart(mappingNode, tupleType); if (getDocumentContext().peek() instanceof Resource) { Resource resource = (Resource) getDocumentContext().peek(); getTemplateResolver().resolve(mappingNode, resource.getRelativeUri(), resource.getUri()); } else if (isBodyBuilder(getBuilderContext().peek())) { getMediaTypeResolver().resolve(mappingNode); } return true; }
@Override public boolean onMappingNodeStart(MappingNode mappingNode, TupleType tupleType) { super.onMappingNodeStart(mappingNode, tupleType); if (getDocumentContext().peek() instanceof Resource) { Resource resource = (Resource) getDocumentContext().peek(); getTemplateResolver().resolve(mappingNode, resource.getRelativeUri(), resource.getUri()); } else if (isBodyBuilder(getBuilderContext().peek())) { getMediaTypeResolver().resolve(mappingNode); } return true; }
private void createHookMethodNoParams( final Resource ramlResource, final JDefinedClass builder, final JDefinedClass builderForParent, final String hookMethodName, final JExpression constructorInvocation) { final JMethod hookMethod = builderForParent.method(JMod.PUBLIC, builder, hookMethodName); hookMethod.body()._return(constructorInvocation); // attach the Javadoc hookMethod .javadoc() .append(JavaDocs.DOCS_METHOD_NO_PARAMS.fillTemplate( ResourceBuilder.class.getCanonicalName(), ramlResource.getRelativeUri(), builder.name())); }
protected void createResourceInterface(final Resource resource) throws Exception { final String resourceInterfaceName = Names.buildResourceInterfaceName(resource); final JDefinedClass resourceInterface = context.createResourceInterface(resourceInterfaceName); context.setCurrentResourceInterface(resourceInterface); final String path = strip(resource.getRelativeUri(), "/"); resourceInterface.annotate(Path.class).param(DEFAULT_ANNOTATION_PARAMETER, StringUtils.defaultIfBlank(path, "/")); if (isNotBlank(resource.getDescription())) { resourceInterface.javadoc().add(resource.getDescription()); } addResourceMethods(resource, resourceInterface, path); }