/** * 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; }
public void empty(Action action) { if (has(Validation.EMPTY)) { if (action.getResponses().isEmpty()) { violation("empty", locator); } } }
private Collection<MimeType> getUniqueResponseMimeTypes(final Action action) { final Map<String, MimeType> responseMimeTypes = new HashMap<String, MimeType>(); for (final Response response : action.getResponses().values()) { if (response.hasBody()) { for (final MimeType responseMimeType : response.getBody().values()) { if (responseMimeType != null) { responseMimeTypes.put(responseMimeType.getType(), responseMimeType); } } } } return responseMimeTypes.values(); }
/** * <p>getUniqueResponseMimeTypes.</p> * * @param action a {@link org.raml.model.Action} object. * @return a {@link java.util.Collection} object. */ protected Collection<MimeType> getUniqueResponseMimeTypes( final Action action) { final Map<String, MimeType> responseMimeTypes = new HashMap<String, MimeType>(); for (final Response response : action.getResponses().values()) { if (response.hasBody()) { for (final MimeType responseMimeType : response.getBody() .values()) { if (responseMimeType != null) { responseMimeTypes.put(responseMimeType.getType(), responseMimeType); } } } } return responseMimeTypes.values(); }
private Collection<String> getUniqueResponseSchema(final Action action) { final Set<String> responseSchemas = new HashSet<>(); for (final Map.Entry<String, Response> responseEntry : action.getResponses().entrySet()) { // consider only successful responses if (!TransformUtils.isErrorResponse(responseEntry.getKey()) && responseEntry.getValue().getBody() != null) { for (final MimeType mimeType : responseEntry.getValue().getBody().values()) { if (mimeType != null) { responseSchemas.add(mimeType.getSchema()); } } } } return responseSchemas; }
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); } }
protected List<Method> transformMethod(final Context context, final String globalMediaType, final org.raml.model.Action source, final List<org.raml.model.Resource> parents, final List<Map<String, SecurityScheme>> allSchemes, final APINamespace namespace, final TransformationContext ctx) { return transformMethod(context, source, parents, allSchemes, toProduces(source.getResponses()), toConsumes(globalMediaType, source), namespace, ctx); }
private Map<String, String> adjustInlineSchema(final Resource singleResource) throws IOException { final ImmutableMap.Builder<String, String> inlinedSchemas = ImmutableMap.builder(); for (final Map.Entry<ActionType, Action> actionEntry : singleResource.getActions().entrySet()) { for (final Map.Entry<String, Response> responseEntry : actionEntry.getValue().getResponses().entrySet()) { if (!TransformUtils.isErrorResponse(responseEntry.getKey())) { final Response response = responseEntry.getValue(); final String schemaName = JSONSchemaNameUtil .getSchemaName(singleResource, actionEntry.getKey(), responseEntry.getKey()); inlinedSchemas.putAll(createSchemas(schemaName, response.getBody())); } } final Action action = actionEntry.getValue(); final String schemaName = JSONSchemaNameUtil.getSchemaName(singleResource, actionEntry.getKey()); inlinedSchemas.putAll(createSchemas(schemaName, action.getBody())); } for (final Resource subResource : singleResource.getResources().values()) { inlinedSchemas.putAll(adjustInlineSchema(subResource)); } return inlinedSchemas.build(); }
@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); } }
Map<String, Response> responses = a.getResponses(); if (responses != null) { for (Response resp : responses.values()) {
private static void createTotalUsage(Usage usage, Map<String, Resource> resources) { for (final Map.Entry<String, Resource> resourceEntry : resources.entrySet()) { resourceUsage(usage, resourceEntry.getValue()); for (final Action action : resourceEntry.getValue().getActions().values()) { actionUsage(usage, action).initQueryParameters(action.getQueryParameters().keySet()); actionUsage(usage, action).initResponseCodes(action.getResponses().keySet()); actionUsage(usage, action).initRequestHeaders(action.getHeaders().keySet()); if (action.getBody() != null) { for (final MimeType mimeType : action.getBody().values()) { if (mimeType.getFormParameters() != null) { UsageBuilder.mimeTypeUsage(usage, action, mimeType).initFormParameters(mimeType.getFormParameters().keySet()); } } } for (final Map.Entry<String, Response> responseEntry : action.getResponses().entrySet()) { responseUsage(usage, action, responseEntry.getKey()).initResponseHeaders(responseEntry.getValue().getHeaders().keySet()); } } createTotalUsage(usage, resourceEntry.getValue().getResources()); } } }
for (Response response : action.getResponses().values())
for (Response response : action.getResponses().values())
if (MediaType.JSON_PATCH.getCode().equals(requestBody.getType())) final Response response = source.getResponses().get("200"); if (response == null)
private JDefinedClass createResourceMethodReturnType(final String methodName, final Action action, final JDefinedClass resourceInterface) throws Exception { final JDefinedClass responseClass = resourceInterface._class(capitalize(methodName) + "Response") ._extends(context.getResponseWrapperType()); final JMethod responseClassConstructor = responseClass.constructor(JMod.PRIVATE); responseClassConstructor.param(javax.ws.rs.core.Response.class, "delegate"); responseClassConstructor.body().invoke("super").arg(JExpr.ref("delegate")); for (final Entry<String, Response> statusCodeAndResponse : action.getResponses().entrySet()) { createResponseBuilderInResourceMethodReturnType(action, responseClass, statusCodeAndResponse); } return responseClass; }
private JDefinedClass createResourceMethodReturnType(final String methodName, final Action action, final JDefinedClass resourceInterface) throws Exception { final JDefinedClass responseClass = resourceInterface._class(capitalize(methodName) + "Response") ._extends(context.getResponseWrapperType()); final JMethod responseClassConstructor = responseClass.constructor(JMod.PRIVATE); responseClassConstructor.param(javax.ws.rs.core.Response.class, "delegate"); responseClassConstructor.body().invoke("super").arg(JExpr.ref("delegate")); for (final Entry<String, Response> statusCodeAndResponse : action.getResponses().entrySet()) { createResponseBuilderInResourceMethodReturnType(action, responseClass, statusCodeAndResponse); } return responseClass; }
@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 MediaTypeMatch doCheckReponse(RamlViolations violations, RamlResponse response, Action action, Map<String, Response> securityResponses) { final Map<String, Response> responseMap = mergeMaps(action.getResponses(), securityResponses); final Response res = responseMap.get(Integer.toString(response.getStatus())); if (res == null) { violations.add("responseCode.undefined", locator, response.getStatus()); return null; } final String statusStr = Integer.toString(response.getStatus()); actionUsage(usage, action).addResponseCode(statusStr); locator.responseCode(statusStr); checkResponseHeaderParameters(violations, response.getHeaderValues(), action, statusStr, res); final MediaTypeMatch typeMatch = MediaTypeMatch.find(violations, response, res.getBody(), locator); if (typeMatch != null) { locator.responseMime(typeMatch.getMatchingMime()); checkSchema(violations, response.getContent(), typeMatch); } return typeMatch; }
createMethodResponses(api, method, action.getResponses(), update);
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()); } }