public void action(Action action) { this.resource = action.getResource(); this.action = action; requestMime = null; responseCode = null; responseMime = null; }
/** * <p>addPathParameters.</p> * * @param action a {@link org.raml.model.Action} object. * @param method a {@link com.sun.codemodel.JMethod} object. * @param javadoc a {@link com.sun.codemodel.JDocComment} object. * @throws java.lang.Exception if any. */ protected void addPathParameters(final Action action, final JMethod method, final JDocComment javadoc) throws Exception { addAllResourcePathParameters(action.getResource(), method, javadoc); }
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()); }
private void addPathParameters(final Action action, final JMethod method, final JDocComment javadoc) throws Exception { addAllResourcePathParameters(action.getResource(), method, javadoc); }
public static Map<String, List<? extends AbstractParam>> getEffectiveBaseUriParams(Map<String, UriParameter> baseUriParams, Action action) { final Map<String, List<? extends AbstractParam>> params = new HashMap<>(); if (action.getBaseUriParameters() != null) { params.putAll(action.getBaseUriParameters()); } addNotSetBaseUriParams(action.getResource(), params); if (baseUriParams != null) { for (final Map.Entry<String, UriParameter> entry : baseUriParams.entrySet()) { if (!params.containsKey(entry.getKey())) { params.put(entry.getKey(), Collections.singletonList(entry.getValue())); } } } return params; }
private void addParamAnnotation(final String resourceInterfacePath, final Action action, final JMethod method) { final String path = StringUtils.substringAfter(action.getResource().getUri(), resourceInterfacePath + "/"); if (isNotBlank(path)) { method.annotate(Path.class).param(DEFAULT_ANNOTATION_PARAMETER, path); } }
/** * Gets the effective trait which is from resource (flat) for this action or for action itself. */ private Map<String, Template> getEffectiveTemplates(final Action source, final TransformationContext context) { final Map<String, Template> result = new LinkedHashMap<>(); result.putAll(getAllTemplatesForResource(context.getRamlModel(), source.getResource())); result.putAll(getAllTemplatesForMethod(context.getRamlModel(), source)); return result; }
/** * <p>addParamAnnotation.</p> * * @param resourceInterfacePath a {@link java.lang.String} object. * @param action a {@link org.raml.model.Action} object. * @param method a {@link com.sun.codemodel.JMethod} object. */ protected void addParamAnnotation(final String resourceInterfacePath, final Action action, final JMethod method) { final String path = StringUtils.substringAfter(action.getResource() .getUri(), resourceInterfacePath + "/"); if (isNotBlank(path)) { method.annotate(Path.class).param(DEFAULT_ANNOTATION_PARAMETER, path); } }
public static String buildResourceMethodName(final Action action, final MimeType bodyMimeType) { final String methodBaseName = buildJavaFriendlyName(action.getResource() .getUri() .replace("{", " By ")); return action.getType().toString().toLowerCase() + buildMimeTypeInfix(bodyMimeType) + methodBaseName; }
/** * <p>buildResourceMethodName.</p> * * @param action a {@link org.raml.model.Action} object. * @param bodyMimeType a {@link org.raml.model.MimeType} object. * @return a {@link java.lang.String} object. */ public static String buildResourceMethodName(final Action action, final MimeType bodyMimeType) { final String methodBaseName = buildJavaFriendlyName(action.getResource() .getUri() .replace("{", " By ")); return action.getType().toString().toLowerCase() + buildMimeTypeInfix(bodyMimeType) + methodBaseName; }
/** * Looks up the {@code ArbitraryActionBuilder} that is to be used as a super-class for the {@link ActionBuilder}s * procreated by this class. * <p/> * Such {@code ArbitraryActionBuilder}s are created by the {@link ArbitraryActionBuilderProcreator}. * * @param ramlAction The {@link Action} for which to find the {@code ArbitraryActionBuilder} * @return The class that represents the {@code ArbitraryActionBuilder} */ protected JDefinedClass lookupArbitraryActionBuilder( final Action ramlAction, final Context<Object, JDeclaration> context) { final JDefinedClass resourceBuilder = context.lookupNode(ramlAction.getResource(), JDefinedClass.class); for (final Iterator<JDefinedClass> it = resourceBuilder.classes(); it.hasNext();) { final JDefinedClass arbitraryActionBuilder = it.next(); if (JavaNameUtils.buildArbitraryActionBuilderName().equals(arbitraryActionBuilder.name())) { return arbitraryActionBuilder; } } return null; }
public List<SecurityScheme> securedBy(Action action) { final List<SecurityScheme> res = new ArrayList<>(); if (!action.getSecuredBy().isEmpty()) { res.addAll(securitySchemes(action.getSecuredBy(), new Message("securityScheme.undefined", new Locator(action)))); } else if (!action.getResource().getSecuredBy().isEmpty()) { res.addAll(securitySchemes(action.getResource().getSecuredBy(), new Message("securityScheme.undefined", new Locator(action.getResource())))); } else if (!raml.getSecuredBy().isEmpty()) { res.addAll(securitySchemes(raml.getSecuredBy(), new Message("securityScheme.undefined", new Locator()))); } if (res.isEmpty()) { res.add(NULL_SCHEMA); } return res; }
private String actionString() { return new Message("action", action.getType(), action.getResource().getUri()).toString(); } }
@Override public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException { final Action a = (Action) o; switch (propertyName) { case "securitySchemes": if (a.getSecuredBy() != null && !a.getSecuredBy().isEmpty()) { return a.getSecuredBy(); } if (a.getResource().getSecuredBy() != null && !a.getResource().getSecuredBy().isEmpty()) { return a.getResource().getSecuredBy(); } if (raml.getSecuredBy() != null && !raml.getSecuredBy().isEmpty()) { return raml.getSecuredBy(); } return Collections.emptyList(); case "type": return a.getType().toString(); case "responses": return new TreeMap<>(a.getResponses()); case "queryParameters": return new TreeMap<>(a.getQueryParameters()); case "headers": return new TreeMap<>(a.getHeaders()); case "body": return a.getBody() == null ? null : new TreeMap<>(a.getBody()); default: return super.getProperty(interp, self, o, property, propertyName); } } }
static Usage.Action actionUsage(Usage usage, Action action) { return usage.resource(action.getResource().getUri()).action(action.getType().name()); }
cleanupMethod(method, "path", action.getResource().getUriParameters().keySet()); cleanupMethod(method, "header", action.getHeaders().keySet()); cleanupMethod(method, "querystring", action.getQueryParameters().keySet());
.name(source.getResource().getDisplayName())// builder.parameters(transformPathParameters(context, namespace, source.getResource())); decorateParametersBySecuritySchema(context, securitySchemes, namespace, source.getResource().getSecuredBy())); builder.responses( decorateResponsesBySecuritySchema(context, securitySchemes, source.getResource().getSecuredBy(), ctx));
+ ramlAction.getResource() + " from the context");