Java Code Examples for org.eclipse.microprofile.openapi.annotations.responses.APIResponse

The following examples show how to use org.eclipse.microprofile.openapi.annotations.responses.APIResponse. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: component-runtime   Source File: ComponentResource.java    License: Apache License 2.0 7 votes vote down vote up
@POST
@Path("migrate/{id}/{configurationVersion}")
@Operation(operationId = "migrateComponent",
        description = "Allows to migrate a component configuration without calling any component execution.")
@APIResponse(responseCode = "200",
        description = "the new configuration for that component (or the same if no migration was needed).",
        content = @Content(mediaType = APPLICATION_JSON))
@APIResponse(responseCode = "404", description = "The component is not found",
        content = @Content(mediaType = APPLICATION_JSON,
                schema = @Schema(type = OBJECT, implementation = ErrorPayload.class)))
Map<String, String> migrate(
        @PathParam("id") @Parameter(name = "id", description = "the component identifier", in = PATH) String id,
        @PathParam("configurationVersion") @Parameter(name = "configurationVersion",
                description = "the configuration version you send", in = PATH) int version,
        @RequestBody(description = "the actual configuration in key/value form.", required = true,
                content = @Content(mediaType = APPLICATION_JSON,
                        schema = @Schema(type = OBJECT))) Map<String, String> config);
 
Example 2
Source Project: quarkus-in-prod   Source File: LegumeApi.java    License: Apache License 2.0 6 votes vote down vote up
@POST
@Path("/init")
@Operation(
        operationId = "ProvisionLegumes",
        summary = "Add default legumes to the Database"
)
@APIResponse(
        responseCode = "201",
        description = "Default legumes created"
)
@APIResponse(
        name = "notFound",
        responseCode = "404",
        description = "Legume provision not found"
)
@APIResponse(
        name = "internalError",
        responseCode = "500",
        description = "Internal Server Error"
)
Response provision();
 
Example 3
Source Project: quarkus-in-prod   Source File: LegumeApi.java    License: Apache License 2.0 6 votes vote down vote up
@Operation(
        operationId = "ListLegumes",
        summary = "List all legumes"
)
@APIResponse(
        responseCode = "200",
        description = "The List with all legumes"
)
@APIResponse(
        name = "notFound",
        responseCode = "404",
        description = "Legume list not found"
)
@APIResponse(
        name = "internalError",
        responseCode = "500",
        description = "Internal Server Error"
)
@GET
List<Legume> list();
 
Example 4
Source Project: microprofile-open-api   Source File: UserResource.java    License: Apache License 2.0 6 votes vote down vote up
@POST
@Path("/createWithArray")
@APIResponse(
        description = "successful operation"
    )
@Operation(
    summary = "Creates list of users with given input array"
)
public Response createUsersWithArrayInput(
    @Parameter(
        description = "List of user object",
        required = true
        ) User[] users) {
            for (User user : users) {
                userData.addUser(user);
        }
    return Response.ok().entity("").build();
}
 
Example 5
Source Project: component-runtime   Source File: DocumentationResource.java    License: Apache License 2.0 6 votes vote down vote up
@GET
@Path("component/{id}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(
        description = "Returns an asciidoctor version of the documentation for the component represented by its identifier `id`.")
@APIResponse(responseCode = "200",
        description = "the list of available and storable configurations (datastore, dataset, ...).",
        content = @Content(mediaType = APPLICATION_JSON))
@APIResponse(responseCode = "404",
        description = "If the component is missing, payload will be an ErrorPayload with the code PLUGIN_MISSING.",
        content = @Content(mediaType = APPLICATION_JSON,
                schema = @Schema(type = OBJECT, implementation = ErrorPayload.class)))
DocumentationContent getDocumentation(
        @PathParam("id") @Parameter(name = "id", description = "the component identifier", in = PATH) String id,
        @QueryParam("language") @DefaultValue("en") @Parameter(name = "language",
                description = "the language for display names.", in = QUERY,
                schema = @Schema(type = STRING, defaultValue = "en")) String language,
        @QueryParam("segment") @DefaultValue("ALL") @Parameter(name = "segment",
                description = "the part of the documentation to extract.", in = QUERY,
                schema = @Schema(type = STRING, defaultValue = "ALL")) DocumentationSegment segment);
 
Example 6
Source Project: smallrye-open-api   Source File: ExtensionParsingTests.java    License: Apache License 2.0 6 votes vote down vote up
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
@Callbacks({
        @Callback(name = "extendedCallback", callbackUrlExpression = "http://localhost:8080/resources/ext-callback", operations = @CallbackOperation(summary = "Get results", extensions = {
                @Extension(name = "x-object", value = "{ \"key\":\"value\" }", parseValue = true),
                @Extension(name = "x-object-unparsed", value = "{ \"key\":\"value\" }"),
                @Extension(name = "x-array", value = "[ \"val1\",\"val2\" ]", parseValue = true),
                @Extension(name = "x-booltrue", value = "true", parseValue = true),
                @Extension(name = "x-boolfalse", value = "false", parseValue = true),
                @Extension(name = "x-number", value = "42", parseValue = true),
                @Extension(name = "x-number-sci", value = "42e55", parseValue = true),
                @Extension(name = "x-positive-number-remains-string", value = "+42", parseValue = true),
                @Extension(name = "x-negative-number", value = "-42", parseValue = true),
                @Extension(name = "x-unparsable-number", value = "-Not.A.Number", parseValue = true)
        }, method = "get", responses = @APIResponse(responseCode = "200", description = "successful operation", content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.ARRAY, implementation = String.class)))))
})
public String get(String data) {
    return data;
}
 
Example 7
Source Project: microprofile-open-api   Source File: UserResource.java    License: Apache License 2.0 6 votes vote down vote up
@POST
@Path("/createWithList")
@APIResponse(
        description = "successful operation"
    )
@Operation(
    summary = "Creates list of users with given input array"
)
public Response createUsersWithListInput(
    @Parameter(
        description = "List of user object",
        required = true) java.util.List<User> users) {
            for (User user : users) {
                userData.addUser(user);
            }
            return Response.ok().entity("").build();
        }
 
Example 8
Source Project: quarkus   Source File: TestResource.java    License: Apache License 2.0 6 votes vote down vote up
@GET
@Path("/openapi/responses/{version}")
@Produces("application/json")
@APIResponses({
        @APIResponse(content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.OBJECT, implementation = MyOpenApiEntityV1.class))),
        @APIResponse(content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.OBJECT, implementation = MyOpenApiEntityV2.class)))
})
public Response openApiResponses(@PathParam("version") String version) {
    if ("v1".equals(version)) {
        MyOpenApiEntityV1 entityV1 = new MyOpenApiEntityV1();
        entityV1.setName("my openapi entity version one name");
        return Response.ok(entityV1).build();
    }

    MyOpenApiEntityV2 entityV2 = new MyOpenApiEntityV2();
    entityV2.setName("my openapi entity version two name");
    entityV2.setValue(version);
    return Response.ok(entityV2).build();
}
 
Example 9
Source Project: microprofile-open-api   Source File: BookingResource.java    License: Apache License 2.0 6 votes vote down vote up
@PUT
@Path("{id}")
@Consumes("application/json")
@Produces("text/plain")
@APIResponse(
        responseCode="200",
        description="Booking updated"
        )
@APIResponse(
        responseCode="404",
        description="Booking not found"
        )
@Operation(
    summary="Update a booking with ID",
    operationId = "updateBookingId")
public Response updateBooking(
    @PathParam("id") int id, Booking booking){
        if(bookings.get(id)!=null){
            bookings.put(id, booking);
            return Response.ok().build();
        }
        else{
            return Response.status(Status.NOT_FOUND).build();
        }
    }
 
Example 10
Source Project: microprofile-open-api   Source File: BookingResource.java    License: Apache License 2.0 6 votes vote down vote up
@DELETE
@Path("{id}")
@Tag()
@APIResponse(
        responseCode="200",
        description="Booking deleted successfully."
    )
@APIResponse(
        responseCode="404",
        description="Booking not found."
    )
@Operation(
    summary="Delete a booking with ID",
    operationId = "deleteBookingById")
@Produces("text/plain")
public Response deleteBooking(
        @PathParam("id") int id){
            if(bookings.get(id)!=null) {
                bookings.remove(id);
                return Response.ok().build();
            }
            else {
                return Response.status(Status.NOT_FOUND).build();
            }
        }
 
Example 11
Source Project: component-runtime   Source File: ComponentResource.java    License: Apache License 2.0 6 votes vote down vote up
@GET
@Path("index")
@Operation(operationId = "getComponentIndex", description = "Returns the list of available components.")
@APIResponse(responseCode = "200", description = "The index of available components.",
        content = @Content(mediaType = APPLICATION_OCTET_STREAM))
ComponentIndices getIndex(
        @QueryParam("language") @DefaultValue("en") @Parameter(name = "language",
                description = "the language for display names.", in = QUERY,
                schema = @Schema(type = STRING, defaultValue = "en")) String language,
        @QueryParam("includeIconContent") @DefaultValue("false") @Parameter(name = "includeIconContent",
                description = "should the icon binary format be included in the payload.", in = QUERY,
                schema = @Schema(type = STRING, defaultValue = "en")) boolean includeIconContent,
        @QueryParam("q") @Parameter(name = "q",
                description = "Query in simple query language to filter components. "
                        + "It provides access to the component `plugin`, `name`, `id` and `metadata` of the first configuration property. "
                        + "Ex: `(id = AYETAE658349453) AND (metadata[configurationtype::type] = dataset) AND (plugin = jdbc-component) AND "
                        + "(name = input)`",
                in = QUERY, schema = @Schema(type = STRING)) String query);
 
Example 12
Source Project: microprofile-open-api   Source File: ReviewResource.java    License: Apache License 2.0 6 votes vote down vote up
@DELETE
@Path("{id}")
@APIResponse(
        responseCode="200",
        description="Review deleted"
        )
@APIResponse(
        responseCode="404",
        description="Review not found"
        )
@Operation(
    summary="Delete a Review with ID",
    operationId = "deleteReview"
    )
@Produces("text/plain")
public Response deleteReview(
        @PathParam("id") int id){
            if(reviews.get(id)!=null) {
                reviews.remove(id);
                return Response.ok().build();
            }
            else {
                return Response.status(Status.NOT_FOUND).build();
            }
        }
 
Example 13
@POST
@Path("migrate/{id}/{configurationVersion}")
@Operation(operationId = "migrateConfiguration",
        description = "Allows to migrate a configuration without calling any component execution.")
@APIResponse(responseCode = "200",
        description = "the new values for that configuration (or the same if no migration was needed).",
        content = @Content(mediaType = APPLICATION_JSON))
@APIResponse(responseCode = "400",
        description = "If the configuration is missing, payload will be an ErrorPayload with the code CONFIGURATION_MISSING.",
        content = @Content(mediaType = APPLICATION_JSON,
                schema = @Schema(type = OBJECT, implementation = ErrorPayload.class)))
@APIResponse(responseCode = "404", description = "The configuration is not found",
        content = @Content(mediaType = APPLICATION_JSON))
Map<String, String> migrate(
        @PathParam("id") @Parameter(name = "id", description = "the configuration identifier", in = PATH) String id,
        @PathParam("configurationVersion") @Parameter(name = "configurationVersion",
                description = "the configuration version you send", in = PATH) int version,
        @RequestBody(description = "the actual configuration in key/value form.", required = true,
                content = @Content(mediaType = APPLICATION_JSON,
                        schema = @Schema(type = OBJECT))) Map<String, String> config);
 
Example 14
Source Project: microprofile-open-api   Source File: UserResource.java    License: Apache License 2.0 6 votes vote down vote up
@GET
@Path("/logout")
@APIResponse(
            responseCode = "200",
            description = "Successful user logout."
            )
@ExternalDocumentation(
        description = "Policy on user security.",
        url = "http://exampleurl.com/policy"
        )
@Operation(
    summary = "Logs out current logged in user session",
    operationId = "logOutUser"
    /* tags = {"user"}, // intentionally removed to have a method with no tags */)
public Response logoutUser() {
return Response.ok().entity("").build();
}
 
Example 15
Source Project: quarkus-in-prod   Source File: LegumeApi.java    License: Apache License 2.0 5 votes vote down vote up
@POST
@Operation(
        operationId = "AddLegume",
        summary = "Add a Legume"
)
@RequestBody(
        content = @Content(
                mediaType = APPLICATION_JSON,
                schema = @Schema(implementation = LegumeNew.class, ref = "legume_new")),
        description = "The Legume to create",
        required = true
)
@APIResponse(
        responseCode = "201",
        description = "Legume created",
        content = @Content(
                mediaType = APPLICATION_JSON,
                schema = @Schema(implementation = Legume.class, ref = "error"))
)
@APIResponse(
        name = "notFound",
        responseCode = "400",
        description = "Legume data is invalid"
)
@APIResponse(
        name = "notFound",
        responseCode = "404",
        description = "Legume provision not found"
)
@APIResponse(
        name = "internalError",
        responseCode = "500",
        description = "Internal Server Error"
)
public Response add(@Valid final LegumeNew legume);
 
Example 16
Source Project: quarkus-in-prod   Source File: LegumeApi.java    License: Apache License 2.0 5 votes vote down vote up
@DELETE
@Path("{id}")
@Operation(
        operationId = "DeleteLegume",
        summary = "Delete a Legume"
)
@APIResponse(
        responseCode = "204",
        description = "Empty response"
)
@APIResponse(
        name = "notFound",
        responseCode = "404",
        description = "Legume not found"
)
@APIResponse(
        name = "internalError",
        responseCode = "500",
        description = "Internal Server Error"
)
Response delete(
        @Parameter(name = "id",
                description = "Id of the Legume to delete",
                required = true,
                example = "81471222-5798-11e9-ae24-57fa13b361e1",
                schema = @Schema(description = "uuid", required = true))
        @PathParam("id")
        @NotEmpty final String legumeId);
 
Example 17
Source Project: microprofile-open-api   Source File: UserResource.java    License: Apache License 2.0 5 votes vote down vote up
@GET
@Path("/logout")
@APIResponse(
        description = "successful operation"
    )
@Operation(
    summary = "Logs out current logged in user session"
)
public Response logoutUser() {
    return Response.ok().entity("").build();
}
 
Example 18
Source Project: smallrye-open-api   Source File: ParameterResource.java    License: Apache License 2.0 5 votes vote down vote up
@DELETE
@Path("/unnamed")
@APIResponse(responseCode = "204", description = "No content")
public Response deleteTaskWithoutParamName(
        @Parameter(description = "The id of the task", example = "e1cb23d0-6cbe-4a29", schema = @Schema(type = SchemaType.STRING)) @PathParam("taskId") String taskId,
        @QueryParam("nextTask") String nextTaskId) {
    return Response.noContent().build();
}
 
Example 19
Source Project: smallrye-open-api   Source File: ParameterResource.java    License: Apache License 2.0 5 votes vote down vote up
@DELETE
@Path("/named")
@APIResponse(responseCode = "204", description = "No content")
public Response deleteTaskWithParamName(
        @Parameter(description = "The id of the task, invalid name discarded when @Parameter and JAX-RS annotation have same target", name = "notTaskId", example = "e1cb23d0-6cbe-4a29", schema = @Schema(type = SchemaType.STRING)) @PathParam("taskId") String taskId) {
    return Response.noContent().build();
}
 
Example 20
Source Project: microprofile-open-api   Source File: PetResource.java    License: Apache License 2.0 5 votes vote down vote up
@GET
@Path("/findByTags")
@Produces("application/json")
@Callback(
    name = "tagsCallback",
    callbackUrlExpression = "http://petstoreapp.com/pet",
    operations = @CallbackOperation(
        method = "GET",
        summary = "Finds Pets by tags",
        description = "Find Pets by tags; Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
        responses = {
            @APIResponse(
                responseCode = "400",
                description = "Invalid tag value",
                content = @Content(mediaType = "none")
            ),
            @APIResponse(
                responseCode = "200",
                content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(type = SchemaType.ARRAY, implementation = Pet.class))
                )
        }
    )
)
@APIResponseSchema(Pet[].class)
@Deprecated
public Response findPetsByTags(
    @HeaderParam("apiKey") String apiKey,
    @Parameter(
        name = "tags",
        description = "Tags to filter by",
        required = true,
        deprecated = true,
        schema = @Schema(implementation = String.class, deprecated = true,
          externalDocs = @ExternalDocumentation(description = "Pet Types", url = "http://example.com/pettypes"),
          enumeration = { "Cat", "Dog", "Lizard" }, defaultValue = "Dog" ))
    @QueryParam("tags") String tags) {
        return Response.ok(petData.findPetByTags(tags)).build();
    }
 
Example 21
Source Project: component-runtime   Source File: ComponentResource.java    License: Apache License 2.0 5 votes vote down vote up
@GET
@Path("details") // bulk mode to avoid to fetch components one by one when reloading a pipeline/job
@Operation(operationId = "getComponentDetail",
        description = "Returns the set of metadata about a few components identified by their 'id'.")
@APIResponse(responseCode = "200", description = "the list of details for the requested components.",
        content = @Content(mediaType = APPLICATION_JSON))
@APIResponse(responseCode = "400", description = "Some identifiers were not valid.",
        content = @Content(mediaType = APPLICATION_JSON,
                schema = @Schema(type = OBJECT, implementation = SampleErrorForBulk.class)))
ComponentDetailList getDetail(
        @QueryParam("language") @DefaultValue("en") @Parameter(name = "language",
                description = "the language for display names.", in = QUERY,
                schema = @Schema(type = STRING, defaultValue = "en")) String language,
        @QueryParam("identifiers") @Parameter(name = "identifiers",
                description = "the component identifiers to request.", in = QUERY) String[] ids);
 
Example 22
Source Project: component-runtime   Source File: BulkReadResource.java    License: Apache License 2.0 5 votes vote down vote up
@POST
@Operation(description = "Takes a request aggregating N other endpoint requests and responds all results "
        + "in a normalized HTTP response representation.")
@APIResponse(responseCode = "200", description = "The request payloads.",
        content = @Content(mediaType = APPLICATION_JSON))
CompletionStage<BulkResponses> bulk(@RequestBody(description = "the action parameters as a flat map of strings",
        required = true, content = @Content(mediaType = APPLICATION_JSON)) final BulkRequests requests);
 
Example 23
@Override
@APIResponse(responseCode = "404", description = "Not Found",
    content = @Content(
        schema = @Schema(implementation = User.class)
    )
)
public Response toResponse(NotFoundException t) {
    return Response.status(404, t.getMessage()).build();
}
 
Example 24
Source Project: smallrye-open-api   Source File: JandexUtilTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEnumValue() {
    Index index = IndexScannerTestBase.indexOf(Implementor2.class);
    ClassInfo clazz = index.getClassByName(DotName.createSimple(Implementor2.class.getName()));
    AnnotationInstance annotation = clazz.method("getData")
            .annotation(DotName.createSimple(APIResponse.class.getName()))
            .value("content")
            .asNestedArray()[0]
                    .value("encoding")
                    .asNestedArray()[0];
    Encoding.Style style = JandexUtil.enumValue(annotation, "style", Encoding.Style.class);
    assertEquals(Encoding.Style.PIPE_DELIMITED, style);
}
 
Example 25
Source Project: smallrye-open-api   Source File: ApiResponseTests.java    License: Apache License 2.0 5 votes vote down vote up
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@APIResponse(responseCode = "200", content = {}, description = "Description 200")
@APIResponse(responseCode = "204", description = "Description 204")
@APIResponse(responseCode = "400", description = "Description 400")
public Pet createOrUpdatePet(Pet pet) {
    return pet;
}
 
Example 26
Source Project: smallrye-open-api   Source File: ApiResponseTests.java    License: Apache License 2.0 5 votes vote down vote up
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@APIResponse(responseCode = "204", description = "Description 204")
@APIResponse(responseCode = "400", description = "Description 400")
public Pet createOrUpdatePet(Pet pet) {
    return pet;
}
 
Example 27
Source Project: smallrye-open-api   Source File: ApiResponseTests.java    License: Apache License 2.0 5 votes vote down vote up
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@APIResponse(responseCode = "200")
@APIResponse(responseCode = "204", description = "Description 204")
@APIResponse(responseCode = "400", description = "Description 400")
public Pet createOrUpdatePet(Pet pet) {
    return pet;
}
 
Example 28
Source Project: smallrye-open-api   Source File: ApiResponseTests.java    License: Apache License 2.0 5 votes vote down vote up
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces("multipart/mixed")
@APIResponse(responseCode = "200")
@APIResponse(responseCode = "400", description = "Description 400")
public MultipartOutput getPetWithPicture() {
    return null;
}
 
Example 29
Source Project: smallrye-open-api   Source File: ApiResponseTests.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@APIResponse(responseCode = "201")
@APIResponse(responseCode = "400", description = "Description 400")
public void createOrUpdatePet(Pet pet) {
}
 
Example 30
Source Project: smallrye-open-api   Source File: ApiResponseTests.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
@Path("{id}")
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@APIResponse(responseCode = "204")
@APIResponse(responseCode = "400", description = "Description 400")
public void deletePet(@PathParam("id") String id) {
}