Search in sources :

Example 66 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project atlasmap by atlasmap.

the class AtlasService method validateMappingRequest.

/**
 * Validates the mapping file.
 * @param mapping mapping
 * @param mappingDefinitionId mapping definition ID
 * @param uriInfo URI info
 * @return {@link Validations} validation result
 */
@PUT
@Path("/mapping/validate/{mappingDefinitionId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Validate Mapping", description = "Validate mapping file")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = Validations.class)), description = "Return a validation result"))
public Response validateMappingRequest(InputStream mapping, @Parameter(description = "Mapping ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId, @Context UriInfo uriInfo) {
    try {
        AtlasMapping atlasMapping = fromJson(mapping, AtlasMapping.class);
        LOG.debug("Validate mappings: {}", atlasMapping.getName());
        return validateMapping(mappingDefinitionId, atlasMapping, uriInfo);
    } catch (AtlasException | IOException e) {
        throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) AtlasException(io.atlasmap.api.AtlasException) 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 67 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project atlasmap by atlasmap.

the class AtlasService method updateMappingRequest.

/**
 * Updates existing mapping file on the server.
 * @param mapping mapping
 * @param mappingDefinitionId mapping definition ID
 * @param uriInfo URI info
 * @return empty response
 */
@POST
@Path("/mapping/{mappingDefinitionId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Update Mapping", description = "Update existing mapping file on the server")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses(@ApiResponse(responseCode = "200", description = "Succeeded"))
public Response updateMappingRequest(InputStream mapping, @Parameter(description = "Mapping Definition ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId, @Context UriInfo uriInfo) {
    ADMArchiveHandler handler = loadExplodedMappingDirectory(mappingDefinitionId);
    UriBuilder builder = uriInfo.getAbsolutePathBuilder();
    try {
        handler.setMappingDefinitionBytes(mapping);
        handler.persist();
        builder.path(handler.getMappingDefinition().getName());
    } catch (AtlasException e) {
        LOG.error("Error saving Mapping Definition file.\n" + e.getMessage(), e);
        throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
    }
    return Response.ok().location(builder.build()).build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ADMArchiveHandler(io.atlasmap.core.ADMArchiveHandler) UriBuilder(javax.ws.rs.core.UriBuilder) AtlasException(io.atlasmap.api.AtlasException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) RequestBody(io.swagger.v3.oas.annotations.parameters.RequestBody)

Example 68 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project atlasmap by atlasmap.

the class AtlasService method createMappingRequest.

/**
 * Saves a file on the server.
 * @param mapping request payload
 * @param mappingFormat file type
 * @param mappingDefinitionId mapping definition ID
 * @param uriInfo URI info
 * @return empty response
 */
@PUT
@Path("/mapping/{mappingFormat}/{mappingDefinitionId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM })
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Create Mapping", description = "Save a mapping file on the server")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses({ @ApiResponse(responseCode = "200", description = "Succeeded"), @ApiResponse(responseCode = "500", description = "Mapping file save error") })
public Response createMappingRequest(InputStream mapping, @Parameter(description = "Mapping Format") @PathParam("mappingFormat") MappingFileType mappingFormat, @Parameter(description = "Mapping ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId, @Context UriInfo uriInfo) {
    LOG.debug("createMappingRequest (save) with format '{}'", mappingFormat);
    UriBuilder builder = uriInfo.getAbsolutePathBuilder();
    ADMArchiveHandler admHandler = loadExplodedMappingDirectory(mappingDefinitionId);
    switch(mappingFormat) {
        case JSON:
            try {
                admHandler.setMappingDefinitionBytes(mapping);
                admHandler.persist();
                if (admHandler.getMappingDefinition() != null) {
                    builder.path(admHandler.getMappingDefinition().getName());
                }
            } catch (AtlasException e) {
                LOG.error("Error saving Mapping Definition file.\n" + e.getMessage(), e);
                throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
            }
            return Response.ok().location(builder.build()).build();
        case GZ:
            LOG.debug("  saveGzippedADMDigestRequest '{}' - ID: {}", admHandler.getGzippedADMDigestFileName(), mappingDefinitionId);
            try {
                admHandler.setGzippedADMDigest(mapping);
                admHandler.persist();
            } catch (AtlasException e) {
                LOG.error("Error saving gzipped ADM digest file.\n" + e.getMessage(), e);
                throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
            }
            builder.path(admHandler.getGzippedADMDigestFileName());
            return Response.ok().location(builder.build()).build();
        case ZIP:
            LOG.debug("  importADMArchiveRequest - ID:'{}'", mappingDefinitionId);
            try {
                admHandler.setIgnoreLibrary(false);
                admHandler.setLibraryDirectory(Paths.get(libFolder));
                admHandler.load(mapping);
                this.libraryLoader.reload();
                admHandler.persist();
                LOG.debug("  importADMArchiveRequest complete - ID:'{}'", mappingDefinitionId);
            } catch (Exception e) {
                LOG.error("Error importing ADM archive.\n" + e.getMessage(), e);
                throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
            }
            builder.path("atlasmap-" + mappingDefinitionId + ".adm");
            return Response.ok().location(builder.build()).build();
        case XML:
            throw new WebApplicationException("XML mapping format is no longer supported. Please use JSON format instead.");
        default:
            throw new WebApplicationException("Unrecognized mapping format: " + mappingFormat, Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ADMArchiveHandler(io.atlasmap.core.ADMArchiveHandler) UriBuilder(javax.ws.rs.core.UriBuilder) AtlasException(io.atlasmap.api.AtlasException) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasException(io.atlasmap.api.AtlasException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) 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 69 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project flow by vaadin.

the class OpenAPIObjectGenerator method createRequestBody.

private RequestBody createRequestBody(MethodDeclaration methodDeclaration, ResolvedTypeParametersMap resolvedTypeParametersMap) {
    Map<String, String> paramsDescription = new HashMap<>();
    methodDeclaration.getJavadoc().ifPresent(javadoc -> {
        for (JavadocBlockTag blockTag : javadoc.getBlockTags()) {
            if (blockTag.getType() == JavadocBlockTag.Type.PARAM) {
                paramsDescription.put(blockTag.getName().orElse(""), blockTag.getContent().toText());
            }
        }
    });
    RequestBody requestBody = new RequestBody();
    Content requestBodyContent = new Content();
    requestBody.content(requestBodyContent);
    MediaType requestBodyObject = new MediaType();
    requestBodyContent.addMediaType("application/json", requestBodyObject);
    Schema requestSchema = new ObjectSchema();
    requestSchema.setRequired(new ArrayList<>());
    requestBodyObject.schema(requestSchema);
    methodDeclaration.getParameters().forEach(parameter -> {
        GeneratorType generatorType = createSchemaType(parameter, resolvedTypeParametersMap);
        Schema paramSchema = parseResolvedTypeToSchema(generatorType, parameter.getAnnotations());
        paramSchema.setDescription("");
        usedTypes.putAll(collectUsedTypesFromSchema(paramSchema));
        String name = (isReservedWord(parameter.getNameAsString()) ? "_" : "").concat(parameter.getNameAsString());
        if (GeneratorUtils.isBlank(paramSchema.get$ref())) {
            paramSchema.description(paramsDescription.remove(parameter.getNameAsString()));
        }
        requestSchema.addProperties(name, paramSchema);
        requestSchema.addRequiredItem(name);
    });
    if (!paramsDescription.isEmpty()) {
        requestSchema.addExtension(EXTENSION_VAADIN_CONNECT_PARAMETERS_DESCRIPTION, new LinkedHashMap<>(paramsDescription));
    }
    return requestBody;
}
Also used : ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Content(io.swagger.v3.oas.models.media.Content) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) MediaType(io.swagger.v3.oas.models.media.MediaType) JavadocBlockTag(com.github.javaparser.javadoc.JavadocBlockTag) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody)

Example 70 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project Singularity by HubSpot.

the class TaskResource method runShellCommand.

@POST
@Path("/task/{taskId}/command")
@Operation(summary = "Run a configured shell command against the given task", responses = { @ApiResponse(responseCode = "400", description = "Given shell command option doesn't exist"), @ApiResponse(responseCode = "403", description = "Given shell command doesn't exist") })
@Consumes({ MediaType.APPLICATION_JSON })
public SingularityTaskShellCommandRequest runShellCommand(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(required = true, description = "Id of the task") @PathParam("taskId") String taskId, @RequestBody(required = true, description = "Object describing the command to be run") final SingularityShellCommand shellCommand) {
    SingularityTaskId taskIdObj = getTaskIdFromStr(taskId);
    authorizationHelper.checkForAuthorizationByTaskId(taskId, user, SingularityAuthorizationScope.WRITE, SingularityUserFacingAction.RUN_SHELL_COMMAND);
    validator.checkActionEnabled(SingularityAction.RUN_SHELL_COMMAND);
    if (!taskManager.isActiveTask(taskIdObj)) {
        throw badRequest("%s is not an active task, can't run %s on it", taskId, shellCommand.getName());
    }
    return startShellCommand(taskIdObj, shellCommand, user);
}
Also used : SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

Test (org.testng.annotations.Test)67 OpenAPI (io.swagger.v3.oas.models.OpenAPI)62 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)59 Schema (io.swagger.v3.oas.models.media.Schema)46 Operation (io.swagger.v3.oas.annotations.Operation)41 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)40 MediaType (io.swagger.v3.oas.models.media.MediaType)36 StringSchema (io.swagger.v3.oas.models.media.StringSchema)35 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)32 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)32 Content (io.swagger.v3.oas.models.media.Content)31 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)28 Operation (io.swagger.v3.oas.models.Operation)27 PathItem (io.swagger.v3.oas.models.PathItem)23 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)21 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)19 Parameter (io.swagger.v3.oas.models.parameters.Parameter)15 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)14 Components (io.swagger.v3.oas.models.Components)13 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)12