Search in sources :

Example 76 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody 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 77 with RequestBody

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

the class JsonService method inspect.

/**
 * Inspect a JSON schema or instance and return a Document object.
 * @param requestIn request
 * @return {@link JsonInspectionResponse}
 */
@POST
@Path("/inspect")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Inspect JSON", description = "Inspect a JSON schema or instance and return a Document object")
@RequestBody(description = "JsonInspectionRequest object", content = @Content(schema = @Schema(implementation = JsonInspectionRequest.class)))
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = JsonInspectionResponse.class)), description = "Return a Document object represented by JsonDocument"))
public Response inspect(InputStream requestIn) {
    JsonInspectionRequest request = fromJson(requestIn, JsonInspectionRequest.class);
    long startTime = System.currentTimeMillis();
    JsonInspectionResponse response = new JsonInspectionResponse();
    JsonDocument d = null;
    try {
        if (request.getType() == null || request.getJsonData() == null) {
            response.setErrorMessage("Json data and Instance or Schema inspection type must be specified in request");
        } else {
            JsonInspectionService s = new JsonInspectionService();
            String jsonData = cleanJsonData(request.getJsonData());
            if (!validJsonData(jsonData)) {
                response.setErrorMessage("Invalid json payload specified");
            } else {
                switch(request.getType()) {
                    case INSTANCE:
                        d = s.inspectJsonDocument(jsonData);
                        break;
                    case SCHEMA:
                        d = s.inspectJsonSchema(jsonData);
                        break;
                    default:
                        response.setErrorMessage("Unsupported inspection type: " + request.getType());
                        break;
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Error inspecting json: " + e.getMessage(), e);
        response.setErrorMessage(e.getMessage());
    } finally {
        response.setExecutionTime(System.currentTimeMillis() - startTime);
    }
    AtlasUtil.excludeNotRequestedFields(d, request.getInspectPaths());
    response.setJsonDocument(d);
    return Response.ok().entity(toJson(response)).build();
}
Also used : JsonInspectionService(io.atlasmap.json.inspect.JsonInspectionService) JsonInspectionResponse(io.atlasmap.json.v2.JsonInspectionResponse) JsonInspectionRequest(io.atlasmap.json.v2.JsonInspectionRequest) JsonDocument(io.atlasmap.json.v2.JsonDocument) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WebApplicationException(javax.ws.rs.WebApplicationException) 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 78 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project snow-owl by b2ihealthcare.

the class CodeSystemUpgradeRestService method upgrade.

@Operation(summary = "Start a Code System dependency upgrade (EXPERIMENTAL)", description = "Starts the upgrade process of a Code System to a newer extensionOf Code System dependency than the current extensionOf.")
@ApiResponses({ @ApiResponse(responseCode = "201", description = "Upgrade created"), @ApiResponse(responseCode = "400", description = "Code System cannot be upgraded") })
@PostMapping(consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(HttpStatus.CREATED)
public Promise<ResponseEntity<Void>> upgrade(@RequestBody final UpgradeRestInput body) {
    final UriComponentsBuilder uriBuilder = createURIBuilder();
    final ResourceURI upgradeOf = new ResourceURI(body.getUpgradeOf());
    final IEventBus bus = getBus();
    return // TODO move this to generic resource controller
    CodeSystemRequests.prepareGetCodeSystem(upgradeOf.getResourceId()).buildAsync().execute(bus).thenWith(codeSystem -> {
        return CodeSystemRequests.prepareUpgrade(upgradeOf, new ResourceURI(body.getExtensionOf())).setResourceId(body.getCodeSystemId()).buildAsync().execute(bus);
    }).then(upgradeCodeSystemId -> {
        return ResponseEntity.created(uriBuilder.pathSegment(upgradeCodeSystemId).build().toUri()).build();
    });
}
Also used : CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) AbstractRestService(com.b2international.snowowl.core.rest.AbstractRestService) Promise(com.b2international.snowowl.core.events.util.Promise) IEventBus(com.b2international.snowowl.eventbus.IEventBus) TimeUnit(java.util.concurrent.TimeUnit) Parameter(io.swagger.v3.oas.annotations.Parameter) HttpStatus(org.springframework.http.HttpStatus) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) Tag(io.swagger.v3.oas.annotations.tags.Tag) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ResponseEntity(org.springframework.http.ResponseEntity) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) NotFoundException(com.b2international.commons.exceptions.NotFoundException) ResourceURI(com.b2international.snowowl.core.ResourceURI) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) ResourceURI(com.b2international.snowowl.core.ResourceURI) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 79 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project snow-owl by b2ihealthcare.

the class CodeSystemUpgradeRestService method sync.

@Operation(summary = "Synchronize upgrade codesystem with the original codesystem (EXPERIMENTAL)", description = "Synchronize any changes on the original code system with the upgrade code system.")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "Upgrade code system synchronized"), @ApiResponse(responseCode = "400", description = "Code system could not be synchronized with the downstream code system") })
@PostMapping(value = "/sync/", consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(HttpStatus.NO_CONTENT)
public void sync(@RequestBody final CodeSystemUpgradeSyncRestInput body) {
    final String codeSystemId = body.getCodeSystemId();
    final ResourceURI source = body.getSource();
    final CodeSystem codeSystem = CodeSystemRequests.prepareSearchCodeSystem().filterById(codeSystemId).buildAsync().execute(getBus()).getSync(1, TimeUnit.MINUTES).first().orElseThrow(() -> new NotFoundException("Code System", codeSystemId));
    CodeSystemRequests.prepareUpgradeSynchronization(codeSystem.getResourceURI(), source).buildAsync().execute(getBus());
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) NotFoundException(com.b2international.commons.exceptions.NotFoundException) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 80 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project snow-owl by b2ihealthcare.

the class RepositoryBranchRestService method createBranch.

@Operation(summary = "Create a new branch", description = "Create a new branch in the SNOMED CT repository.")
@ApiResponses({ @ApiResponse(responseCode = "201", description = "Created"), @ApiResponse(responseCode = "400", description = "Bad Request") })
@RequestMapping(method = RequestMethod.POST, consumes = { AbstractRestService.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE })
@ResponseStatus(HttpStatus.CREATED)
public Promise<ResponseEntity<Void>> createBranch(@RequestBody CreateBranchRestRequest request) {
    ApiValidation.checkInput(request);
    final URI location = getResourceLocationURI(request.path());
    return RepositoryRequests.branching().prepareCreate().setParent(request.getParent()).setName(request.getName()).setMetadata(request.metadata()).build(repositoryId).execute(getBus()).then(success -> ResponseEntity.created(location).build());
}
Also used : URI(java.net.URI) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

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