Search in sources :

Example 71 with ApiResponses

use of io.swagger.v3.oas.annotations.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 72 with ApiResponses

use of io.swagger.v3.oas.annotations.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 73 with ApiResponses

use of io.swagger.v3.oas.annotations.responses.ApiResponses in project carbon-apimgt by wso2.

the class OAS3Parser method createOperation.

/**
 * Creates a new operation object using the URI template object
 *
 * @param resource API resource data
 * @return a new operation object using the URI template object
 */
private Operation createOperation(SwaggerData.Resource resource) {
    Operation operation = new Operation();
    populatePathParameters(operation, resource.getPath());
    updateOperationManagedInfo(resource, operation);
    ApiResponses apiResponses = new ApiResponses();
    ApiResponse apiResponse = new ApiResponse();
    apiResponse.description("OK");
    apiResponses.addApiResponse(APIConstants.SWAGGER_RESPONSE_200, apiResponse);
    operation.setResponses(apiResponses);
    return operation;
}
Also used : Operation(io.swagger.v3.oas.models.Operation) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse)

Example 74 with ApiResponses

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

the class AtlasService method processMappingRequest.

/**
 * Processes mapping by feeding input data.
 * @param request request
 * @param uriInfo URI info
 * @return {@link ProcessMappingResponse} which holds the result of the mappings
 */
@PUT
@Path("/mapping/process")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Process Mapping", description = "Process Mapping by feeding input data")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses({ @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ProcessMappingResponse.class)), description = "Return a mapping result"), @ApiResponse(responseCode = "204", description = "Skipped empty mapping execution") })
public Response processMappingRequest(InputStream request, @Context UriInfo uriInfo) {
    ProcessMappingRequest pmr = fromJson(request, ProcessMappingRequest.class);
    if (pmr.getAtlasMapping() != null) {
        throw new WebApplicationException("Whole mapping execution is not yet supported");
    }
    Mapping mapping = pmr.getMapping();
    if (mapping == null) {
        return Response.noContent().build();
    }
    Audits audits = null;
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Preview request: {}", new String(toJson(mapping)));
        }
        audits = previewContext.processPreview(mapping);
    } catch (AtlasException e) {
        throw new WebApplicationException("Unable to process mapping preview", e);
    }
    ProcessMappingResponse response = new ProcessMappingResponse();
    response.setMapping(mapping);
    if (audits != null) {
        response.setAudits(audits);
    }
    byte[] serialized = toJson(response);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Preview outcome: {}", new String(serialized));
    }
    return Response.ok().entity(serialized).build();
}
Also used : Audits(io.atlasmap.v2.Audits) WebApplicationException(javax.ws.rs.WebApplicationException) ProcessMappingResponse(io.atlasmap.v2.ProcessMappingResponse) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasException(io.atlasmap.api.AtlasException) ProcessMappingRequest(io.atlasmap.v2.ProcessMappingRequest) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) RequestBody(io.swagger.v3.oas.annotations.parameters.RequestBody)

Example 75 with ApiResponses

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

the class AtlasService method removeMappingRequest.

/**
 * Remove a mapping file saved on the backend.
 * @param mappingDefinitionId mapping definition ID
 * @return empty response
 */
@DELETE
@Path("/mapping/{mappingDefinitionId}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Remove Mapping", description = "Remove a mapping file saved on the server")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "Specified mapping file was removed successfully"), @ApiResponse(responseCode = "204", description = "Mapping file was not found") })
public Response removeMappingRequest(@Parameter(description = "Mapping ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId) {
    java.nio.file.Path mappingDirPath = Paths.get(getMappingSubDirectory(mappingDefinitionId));
    File mappingDirFile = mappingDirPath.toFile();
    if (mappingDirFile == null || !mappingDirFile.exists()) {
        return Response.noContent().build();
    }
    if (!mappingDirFile.isDirectory()) {
        LOG.warn("Removing invalid file '{}' in a persistent directory", mappingDirFile.getAbsolutePath());
    } else {
        AtlasUtil.deleteDirectory(mappingDirFile);
    }
    return Response.ok().build();
}
Also used : File(java.io.File) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

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)47 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)47 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)46 Operation (io.swagger.v3.oas.models.Operation)39 OpenAPI (io.swagger.v3.oas.models.OpenAPI)34 PathItem (io.swagger.v3.oas.models.PathItem)34 Test (org.testng.annotations.Test)31 ArrayList (java.util.ArrayList)23 Schema (io.swagger.v3.oas.models.media.Schema)22 StringSchema (io.swagger.v3.oas.models.media.StringSchema)21 Content (io.swagger.v3.oas.models.media.Content)20 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