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); } }
@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); } }
addResourceMethods(resourceInterface, resource, resourceInterfacePath, action, null, false); } else if (action.getBody().size() == 1) { final MimeType bodyMimeType = action.getBody().values() .iterator().next(); addResourceMethods(resourceInterface, resource, resourceInterfacePath, action, bodyMimeType, false); } else { for (final MimeType bodyMimeType : action.getBody().values()) { addResourceMethods(resourceInterface, resource, resourceInterfacePath, action, bodyMimeType, true);
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(); }
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()); } } }
Map<String, MimeType> body = a.getBody(); if (body != null) { for (MimeType mt : body.values()) {
@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()); } }
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)); for (Map.Entry<String, MimeType> entry : action.getBody().entrySet()) { final String mime = entry.getKey(); final String modelName = createModel(api, mime, entry.getValue());
LOGGER.log(Level.WARNING, "Error when writting sample.", e); action.getBody().put(mediaType, ramlInRepresentationWithMediaType);
LOGGER.log(Level.WARNING, "Error when writting sample.", e); action.getBody().put(mediaType, ramlInRepresentationWithMediaType);
LOGGER.log(Level.WARNING, "Error when writting sample.", e); action.getBody().put(mediaType, ramlInRepresentationWithMediaType);
LOGGER.log(Level.WARNING, "Error when writting sample.", e); action.getBody().put(mediaType, ramlInRepresentationWithMediaType);
LOGGER.log(Level.WARNING, "Error when writting sample.", e); action.getBody().put(mediaType, ramlInRepresentationWithMediaType);
public void checkRequest(RamlRequest request, Action action, SecurityExtractor security) { checkQueryParameters(request.getQueryValues(), action, security); checkRequestHeaderParameters(request.getHeaderValues(), action, security); final MediaTypeMatch typeMatch = MediaTypeMatch.find(requestViolations, request, action.getBody(), locator); if (typeMatch != null) { locator.requestMime(typeMatch.getMatchingMime()); if (FormDecoder.supportsFormParameters(typeMatch.getTargetType())) { checkFormParameters(action, request.getFormValues(), typeMatch.getMatchingMime()); } else { checkSchema(requestViolations, request.getContent(), typeMatch); } } }