Search in sources :

Example 11 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project atlasmap by atlasmap.

the class AtlasService method listMappings.

/**
 * Retrieves a list of mapping file name saved with specified mapping definition ID.
 * @param uriInfo URI info
 * @param filter filter
 * @param mappingDefinitionId mapping definition ID
 * @return A list of mapping file name in {@link StringMap}
 */
@GET
@Path("/mappings/{mappingDefinitionId}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "List Mappings", description = "Retrieves a list of mapping file name saved with specified mappingDefinitionId")
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = StringMap.class)), description = "Return a list of a pair of mapping file name and content"))
public Response listMappings(@Context UriInfo uriInfo, @QueryParam("filter") final String filter, @Parameter(description = "Mapping Definition ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId) {
    StringMap sMap = new StringMap();
    LOG.debug("listMappings with filter '{}'", filter);
    ADMArchiveHandler handler = loadExplodedMappingDirectory(mappingDefinitionId);
    AtlasMapping map = handler.getMappingDefinition();
    if (map == null) {
        return Response.ok().entity(toJson(sMap)).build();
    }
    StringMapEntry mapEntry = new StringMapEntry();
    mapEntry.setName(map.getName());
    UriBuilder builder = uriInfo.getBaseUriBuilder().path("v2").path("atlas").path("mapping").path(map.getName());
    mapEntry.setValue(builder.build().toString());
    sMap.getStringMapEntry().add(mapEntry);
    byte[] serialized = toJson(sMap);
    if (LOG.isDebugEnabled()) {
        LOG.debug(new String(serialized));
    }
    return Response.ok().entity(serialized).build();
}
Also used : StringMap(io.atlasmap.v2.StringMap) AtlasMapping(io.atlasmap.v2.AtlasMapping) StringMapEntry(io.atlasmap.v2.StringMapEntry) ADMArchiveHandler(io.atlasmap.core.ADMArchiveHandler) UriBuilder(javax.ws.rs.core.UriBuilder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 12 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project flow by vaadin.

the class OpenAPIObjectGenerator method createPathItems.

private Map<String, PathItem> createPathItems(String endpointName, String tagName, ClassOrInterfaceDeclaration typeDeclaration, ResolvedTypeParametersMap resolvedTypeParametersMap, CompilationUnit compilationUnit) {
    Map<String, PathItem> newPathItems = new HashMap<>();
    Collection<MethodDeclaration> methods = typeDeclaration.getMethods();
    for (MethodDeclaration methodDeclaration : methods) {
        if (isAccessForbidden(typeDeclaration, methodDeclaration)) {
            continue;
        }
        String methodName = methodDeclaration.getNameAsString();
        Operation post = createPostOperation(methodDeclaration);
        if (methodDeclaration.getParameters().isNonEmpty()) {
            post.setRequestBody(createRequestBody(methodDeclaration, resolvedTypeParametersMap));
        }
        ApiResponses responses = createApiResponses(methodDeclaration, resolvedTypeParametersMap);
        post.setResponses(responses);
        post.tags(Collections.singletonList(tagName));
        PathItem pathItem = new PathItem().post(post);
        String pathName = "/" + endpointName + "/" + methodName;
        pathItem.readOperationsMap().forEach((httpMethod, operation) -> operation.setOperationId(String.join("_", endpointName, methodName, httpMethod.name())));
        newPathItems.put(pathName, pathItem);
    }
    Stream.concat(typeDeclaration.getExtendedTypes().stream(), typeDeclaration.getImplementedTypes().stream()).map(resolvedType -> getDeclarationAndResolvedTypeParametersMap(resolvedType, resolvedTypeParametersMap)).filter(Objects::nonNull).forEach(pair -> newPathItems.putAll(createPathItems(endpointName, tagName, pair.a, pair.b, compilationUnit)));
    return newPathItems;
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Operation(io.swagger.v3.oas.models.Operation) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses)

Example 13 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project swagger-parser by swagger-api.

the class OpenAPIDeserializer method getOperation.

public Operation getOperation(ObjectNode obj, String location, ParseResult result) {
    if (obj == null) {
        return null;
    }
    Operation operation = new Operation();
    ArrayNode array = getArray("tags", obj, false, location, result);
    List<String> tags = getTagsStrings(array, String.format("%s.%s", location, "tags"), result);
    if (tags != null) {
        operation.setTags(tags);
    }
    String value = getString("summary", obj, false, location, result);
    if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
        operation.setSummary(value);
    }
    value = getString("description", obj, false, location, result);
    if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
        operation.setDescription(value);
    }
    ObjectNode externalDocs = getObject("externalDocs", obj, false, location, result);
    ExternalDocumentation docs = getExternalDocs(externalDocs, String.format("%s.%s", location, "externalDocs"), result);
    if (docs != null) {
        operation.setExternalDocs(docs);
    }
    value = getString("operationId", obj, false, location, result, operationIDs);
    if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
        operation.operationId(value);
    }
    ArrayNode parameters = getArray("parameters", obj, false, location, result);
    if (parameters != null) {
        operation.setParameters(getParameterList(parameters, String.format("%s.%s", location, "parameters"), result));
    }
    final ObjectNode requestObjectNode = getObject("requestBody", obj, false, location, result);
    if (requestObjectNode != null) {
        operation.setRequestBody(getRequestBody(requestObjectNode, String.format("%s.%s", location, "requestBody"), result));
    }
    ObjectNode responsesNode = getObject("responses", obj, true, location, result);
    ApiResponses responses = getResponses(responsesNode, String.format("%s.%s", location, "responses"), result, false);
    if (responses != null) {
        operation.setResponses(responses);
    }
    ObjectNode callbacksNode = getObject("callbacks", obj, false, location, result);
    Map<String, Callback> callbacks = getCallbacks(callbacksNode, String.format("%s.%s", location, "callbacks"), result, false);
    if (callbacks != null) {
        operation.setCallbacks(callbacks);
    }
    Boolean deprecated = getBoolean("deprecated", obj, false, location, result);
    if (deprecated != null) {
        operation.setDeprecated(deprecated);
    }
    array = getArray("servers", obj, false, location, result);
    if (array != null && array.size() > 0) {
        operation.setServers(getServersList(array, String.format("%s.%s", location, "servers"), result));
    }
    array = getArray("security", obj, false, location, result);
    if (array != null) {
        operation.setSecurity(getSecurityRequirementsList(array, String.format("%s.%s", location, "security"), result));
    }
    Map<String, Object> extensions = getExtensions(obj);
    if (extensions != null && extensions.size() > 0) {
        operation.setExtensions(extensions);
    }
    Set<String> keys = getKeys(obj);
    for (String key : keys) {
        if (!OPERATION_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, obj.get(key));
        }
    }
    return operation;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Operation(io.swagger.v3.oas.models.Operation) ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation) Callback(io.swagger.v3.oas.models.callbacks.Callback) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses)

Example 14 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project swagger-parser by swagger-api.

the class ResolverFully method resolvePath.

public void resolvePath(PathItem pathItem) {
    for (Operation op : pathItem.readOperations()) {
        // inputs
        if (op.getParameters() != null) {
            for (Parameter parameter : op.getParameters()) {
                parameter = parameter.get$ref() != null ? resolveParameter(parameter) : parameter;
                if (parameter.getSchema() != null) {
                    Schema resolved = resolveSchema(parameter.getSchema());
                    if (resolved != null) {
                        parameter.setSchema(resolved);
                    }
                }
                if (parameter.getContent() != null) {
                    Map<String, MediaType> content = parameter.getContent();
                    for (String key : content.keySet()) {
                        if (content.get(key) != null && content.get(key).getSchema() != null) {
                            Schema resolvedSchema = resolveSchema(content.get(key).getSchema());
                            if (resolvedSchema != null) {
                                content.get(key).setSchema(resolvedSchema);
                            }
                        }
                    }
                }
            }
        }
        if (op.getCallbacks() != null) {
            Map<String, Callback> callbacks = op.getCallbacks();
            for (String name : callbacks.keySet()) {
                Callback callback = callbacks.get(name);
                callback = callback.get$ref() != null ? resolveCallback(callback) : callback;
                if (callback != null) {
                    for (String callbackName : callback.keySet()) {
                        PathItem path = callback.get(callbackName);
                        if (path != null) {
                            resolvePath(path);
                        }
                    }
                }
                op.getCallbacks().put(name, callback);
            }
        }
        RequestBody refRequestBody = op.getRequestBody();
        if (refRequestBody != null) {
            RequestBody requestBody = refRequestBody.get$ref() != null ? resolveRequestBody(refRequestBody) : refRequestBody;
            op.setRequestBody(requestBody);
            if (requestBody.getContent() != null) {
                Map<String, MediaType> content = requestBody.getContent();
                for (String key : content.keySet()) {
                    if (content.get(key) != null && content.get(key).getSchema() != null) {
                        Schema resolved = resolveSchema(content.get(key).getSchema());
                        if (resolved != null) {
                            content.get(key).setSchema(resolved);
                        }
                    }
                }
            }
        }
        // responses
        ApiResponses responses = op.getResponses();
        if (responses != null) {
            for (String code : responses.keySet()) {
                ApiResponse response = responses.get(code);
                if (response.getContent() != null) {
                    Map<String, MediaType> content = response.getContent();
                    for (String mediaType : content.keySet()) {
                        if (content.get(mediaType).getSchema() != null) {
                            Schema resolved = resolveSchema(content.get(mediaType).getSchema());
                            response.getContent().get(mediaType).setSchema(resolved);
                        }
                        if (content.get(mediaType).getExamples() != null) {
                            Map<String, Example> resolved = resolveExample(content.get(mediaType).getExamples());
                            response.getContent().get(mediaType).setExamples(resolved);
                        }
                    }
                }
                resolveHeaders(response.getHeaders());
                Map<String, Link> links = response.getLinks();
                if (links != null) {
                    for (Map.Entry<String, Link> link : links.entrySet()) {
                        Link value = link.getValue();
                        Link resolvedValue = value.get$ref() != null ? resolveLink(value) : value;
                        link.setValue(resolvedValue);
                    }
                }
            }
        }
    }
}
Also used : Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) PathItem(io.swagger.v3.oas.models.PathItem) Callback(io.swagger.v3.oas.models.callbacks.Callback) Example(io.swagger.v3.oas.models.examples.Example) Parameter(io.swagger.v3.oas.models.parameters.Parameter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) Link(io.swagger.v3.oas.models.links.Link) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody)

Example 15 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method testResponseRemoteRefs.

private void testResponseRemoteRefs(String remoteRef) {
    final OpenAPI swagger = new OpenAPI();
    swagger.path("/fun", new PathItem().get(new Operation().responses(new ApiResponses().addApiResponse("200", new ApiResponse().content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref(remoteRef))))))));
    final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
    final ApiResponse response = swagger.getPaths().get("/fun").getGet().getResponses().get("200");
    final Schema ref = response.getContent().get("*/*").getSchema();
    assertEquals(ref.get$ref(), "#/components/schemas/Tag");
    assertNotNull(swagger.getComponents().getSchemas().get("Tag"));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Content(io.swagger.v3.oas.models.media.Content) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MediaType(io.swagger.v3.oas.models.media.MediaType) OpenAPIResolver(io.swagger.v3.parser.OpenAPIResolver) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)99 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)48 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)47 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)47 Operation (io.swagger.v3.oas.models.Operation)39 PathItem (io.swagger.v3.oas.models.PathItem)35 OpenAPI (io.swagger.v3.oas.models.OpenAPI)34 Test (org.testng.annotations.Test)31 ArrayList (java.util.ArrayList)23 Schema (io.swagger.v3.oas.models.media.Schema)22 Content (io.swagger.v3.oas.models.media.Content)21 StringSchema (io.swagger.v3.oas.models.media.StringSchema)21 MediaType (io.swagger.v3.oas.models.media.MediaType)20 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)19 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)17 Path (javax.ws.rs.Path)17 Produces (javax.ws.rs.Produces)17 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)16 Components (io.swagger.v3.oas.models.Components)10