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);
}
}
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();
}
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);
}
}
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;
}
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);
}
Aggregations