@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); } } }
private void action(Action action) { locator.action(action); checker.parameters(action.getBaseUriParameters(), BASE_URI); checker.parameters(action.getQueryParameters(), QUERY); checker.headerPattern(action.getHeaders().keySet()); checker.description(action.getDescription()); checker.description(action.getBaseUriParameters(), BASE_URI); checker.description(action.getQueryParameters(), QUERY); checker.description(action.getHeaders(), HEADER); checker.empty(action); if (action.getBody() != null) { for (final MimeType mimeType : action.getBody().values()) { locator.requestMime(mimeType); mimeType(mimeType); } } for (final Map.Entry<String, Response> entry : action.getResponses().entrySet()) { locator.responseCode(entry.getKey()); response(entry.getValue()); } }
@Override public Map<ActionType, Action> resolve(final Resource resource) { final ImmutableMap.Builder<ActionType, Action> actions = ImmutableMap.builder(); for (final Method m : resource.getMethods()) { final Action action = new Action(); action.setDescription(m.getDescription()); action.setBody(bodyParamResolver.resolve(m)); action.setQueryParameters(queryParamsResolver.resolve(getParametersFor(m.getParameters(), ParameterType.QUERY))); action.setHeaders(headerParamsResolver.resolve(getParametersFor(m.getParameters(), ParameterType.HEADER))); // action.setResource(); action.setResponses(responseResolver.resolve(m)); actions.put(getActionType(m.getMethodType()), action); } return actions.build(); }
/** * Create a placeholder {@link Action} associated with the given {@code Resource}, which is used to procreate an * AnyActionBuilder for the {@code Resource}. */ private static Action asAnyAction(final Resource resource) { final Action anyAction = new Action(); anyAction.setResource(resource); return anyAction; }
private void loadSchemas(Action action) { if (action.getBody() != null) { for (final MimeType mime : action.getBody().values()) { loadSchema(mime); } } for (final Response response : action.getResponses().values()) { loadSchemas(response); } }
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; }
ramlResource.setActions(new LinkedHashMap<ActionType, Action>()); for (Operation operation : resource.getOperations()) { action = new Action(); action.setDescription(operation.getDescription()); action.setResource(ramlResource); action.setQueryParameters(new LinkedHashMap<String, org.raml.model.parameter.QueryParameter>()); for (QueryParameter queryParameter : operation .getQueryParameters()) { ramlQueryParameter.setRepeat(queryParameter .isAllowMultiple()); action.getQueryParameters().put(queryParameter.getName(), ramlQueryParameter); action.setResponses(new LinkedHashMap<String, org.raml.model.Response>()); for (Response response : operation.getResponses()) { org.raml.model.Response ramlResponse = new org.raml.model.Response(); action.getResponses().put( Integer.toString(response.getCode()), ramlResponse);
@Override public void apply(Action action, ResourceClassBuilder resourceClassBuilder) { LOG.info("Process action {}", action); resourceClassBuilder.getApiClass().withMethod( new ActionMethod(resourceClassBuilder.getReq(), resourceClassBuilder.getResp(), resourceClassBuilder.getUri(), action)); action.getQueryParameters().forEach(resourceClassBuilder.applyParamRule); action.getHeaders().forEach(resourceClassBuilder.applyParamRule); if (action.getBody() != null) { action.getBody().values().forEach(resourceClassBuilder.applyBodyRule); } action.getResponses().values().forEach(resourceClassBuilder.applyResponseRule); } }
if (action.hasBody()) { for (Map.Entry<String, MimeType> entry : action.getBody().entrySet()) { final String mime = entry.getKey(); final String modelName = createModel(api, mime, entry.getValue()); cleanupMethodModels(method, action.getBody()); } else { LOG.info(format("Creating method for api id %s and resource id %s with method %s", api.getId(), resource.getId(), httpMethod)); input.setRequestModels(new HashMap<>()); if (action.hasBody()) { for (Map.Entry<String, MimeType> entry : action.getBody().entrySet()) { final String mime = entry.getKey(); final String modelName = createModel(api, mime, entry.getValue()); for (Map.Entry<String, Header> entry : action.getHeaders().entrySet()) { updateMethod(api, method, "header", entry.getKey(), entry.getValue().isRequired()); for (Map.Entry<String, QueryParameter> entry : action.getQueryParameters().entrySet()) { updateMethod(api, method, "querystring", entry.getKey(), entry.getValue().isRequired()); cleanupMethod(method, "path", action.getResource().getUriParameters().keySet()); cleanupMethod(method, "header", action.getHeaders().keySet()); cleanupMethod(method, "querystring", action.getQueryParameters().keySet()); createMethodResponses(api, method, action.getResponses(), update);
.description(source.getDescription())// .methodType(TransformUtils.transform(source.getType()))// .name(source.getResource().getDisplayName())// .qualifier(buildResourceMethodName(source, parents, TransformUtils.transform(source.getType()), null))// builder.parameters(transformPathParameters(context, namespace, source.getResource())); if (source.getBody() != null) final MimeType requestBody = source.getBody().get(bodyType); builder.parameters(transformBodyParam(context, source, requestBody, ctx)); final List<SecurityReference> directSecuredBy = source.getSecuredBy(); decorateParametersBySecuritySchema(context, securitySchemes, namespace, source.getResource().getSecuredBy())); builder.responses( decorateResponsesBySecuritySchema(context, securitySchemes, source.getResource().getSecuredBy(), ctx)); for (final Map.Entry<String, Response> responseEntry : source.getResponses().entrySet()) if (source.getBody() != null && !source.getBody().isEmpty())
/** * Adds methods for adding error callbacks to the target action builder. * * @param ramlAction the action of the action builder * @param builder the action builder * @return the created methods */ protected List<JMethod> createCallbackMethods( final Action ramlAction, final JDefinedClass builder) { final List<JMethod> result = new ArrayList<JMethod>(); ramlAction .getResponses() .keySet() .forEach(errorCode -> maybeCreateCallbackMethod(errorCode, builder).ifPresent(method -> result.add(method))); return result; }
private String actionString() { return new Message("action", action.getType(), action.getResource().getUri()).toString(); } }
private void addQueryParameters(final Action action, final JMethod method, final JDocComment javadoc) throws Exception { for (final Entry<String, QueryParameter> namedQueryParameter : action.getQueryParameters().entrySet()) { addParameter(namedQueryParameter.getKey(), namedQueryParameter.getValue(), QueryParam.class, method, javadoc); } }
private JDocComment addBaseJavaDoc(final Action action, final JMethod method) { final JDocComment javadoc = method.javadoc(); if (isNotBlank(action.getDescription())) { javadoc.add(action.getDescription()); } return javadoc; }
@Override public Collection<Parameter> transform(final Context context, final Action source, final TransformationContext ctx) { final Map<String, Template> effectiveTemplates = getEffectiveTemplates(source, ctx); final List<Parameter> params = new ArrayList<>(); params.addAll( transformParameters(context, methodQueryParametersTransformer, source.getQueryParameters(), ctx.getNamespace(), effectiveTemplates)); params.addAll(transformParameters(context, methodHeaderParametersTransformer, source.getHeaders(), ctx.getNamespace(), effectiveTemplates)); return params; }
private void addResourceMethods(final Resource resource, final JDefinedClass resourceInterface, final String resourceInterfacePath) throws Exception { for (final Action action : resource.getActions().values()) { if (!action.hasBody()) { addResourceMethods(resourceInterface, resourceInterfacePath, action, null, false); } else if (action.getBody().size() == 1) { final MimeType bodyMimeType = action.getBody().values().iterator().next(); addResourceMethods(resourceInterface, resourceInterfacePath, action, bodyMimeType, false); } else { for (final MimeType bodyMimeType : action.getBody().values()) { addResourceMethods(resourceInterface, resourceInterfacePath, action, bodyMimeType, true); } } } for (final Resource childResource : resource.getResources().values()) { addResourceMethods(childResource, resourceInterface, resourceInterfacePath); } }
public void action(Action action) { this.resource = action.getResource(); this.action = action; requestMime = null; responseCode = null; responseMime = null; }