Java Code Examples for org.eclipse.microprofile.openapi.annotations.enums.SchemaType#STRING

The following examples show how to use org.eclipse.microprofile.openapi.annotations.enums.SchemaType#STRING . 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 File: ParameterResource.java    From smallrye-open-api with 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 2
Source File: UserResource.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/login")
@APIResponse(
        responseCode = "200",
        description = "successful operation",
        content = @Content(
            schema = @Schema(implementation = String.class)
        )
    )
@APIResponse(
        responseCode = "400",
        description = "Invalid username/password supplied",
        content = @Content(
            schema = @Schema(implementation = String.class)
        )
    )
@Operation(
    summary = "Logs user into the system"
)
public Response loginUser(
    @Parameter(
        name = "username",
        description = "The user name for login",
        schema = @Schema(type = SchemaType.STRING),
        required = true
    )
    @QueryParam("username") String username,
    @Parameter(
        name = "password",
        description = "The password for login in clear text",
        schema = @Schema(type = SchemaType.STRING),
        required = true)
    @QueryParam("password") String password) {
        return Response.ok()
        .entity("logged in user session:" + System.currentTimeMillis())
        .build();
    }
 
Example 3
Source File: UserResource.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@DELETE
@Path("/{username}")
@APIResponses(value={
        @APIResponse(
                responseCode = "400",
                description = "Invalid username supplied"
            ),
            @APIResponse(
                responseCode = "404",
                description = "User not found"
            )
})
@Operation(
    summary = "Delete user",
    description = "This can only be done by the logged in user."
)
public Response deleteUser(
    @Parameter(
        name = "username",
        description = "The name that needs to be deleted",
        schema = @Schema(type = SchemaType.STRING),
        required = true
    )
    @PathParam("username") String username) {
        if (userData.removeUser(username)) {
            return Response.ok().entity("").build();
        }
        else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    }
 
Example 4
Source File: UserResource.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@PUT
@Path("/{username}")
@APIResponse(
        responseCode = "400",
        description = "Invalid user supplied"
    )
@APIResponse(
        responseCode = "404",
        description = "User not found"
    )
@Operation(
    summary = "Updated user",
    description = "This can only be done by the logged in user."
)
@SecurityRequirementsSet(
    value = {
        @SecurityRequirement(
            name = "userApiKey"
        ),
        @SecurityRequirement(
            name = "userBearerHttp"
        )
    }
)
public Response updateUser(
    @Parameter(
        name = "username",
        description = "name that need to be deleted",
        schema = @Schema(type = SchemaType.STRING),
        required = true
    )
    @PathParam("username") String username,
    @Parameter(
        description = "Updated user object",
        required = true) User user) {
            userData.addUser(user);
            return Response.ok().entity("").build();
        }
 
Example 5
Source File: UserResource.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/{username}")
@Tag(ref="user")
@APIResponses(value={
        @APIResponse(
                responseCode = "200",
                description = "Successfully retrieved user by user name.",
                content = @Content(
                    schema = @Schema(implementation = User.class)
                )),
            @APIResponse(
                responseCode = "400",
                description = "Invalid username supplied",
                content = @Content(
                        schema = @Schema(implementation = User.class)
                ))
})
@Operation(
    summary = "Get user by user name",
    operationId = "getUserByName")
public Response getUserByName(
    @Parameter(
        name = "username",
        schema = @Schema(type = SchemaType.STRING),
        required = true
        )
    @PathParam("username") String userName) throws NotFoundException {
        User user = userData.findUserByName(userName);
        if (null != user) {
            return Response.ok().entity(user).build();
        }
        else {
            throw new NotFoundException("User not found");
        }
    }
 
Example 6
Source File: UserResource.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@DELETE
  @Path("/{username}")
  @Tag(ref="user")
  @APIResponse(
          responseCode = "200",
          description = "User deleted successfully"
          )
  @APIResponse(
          responseCode = "400",
          description = "Invalid username supplied"
          )
  @APIResponse(
          responseCode = "404",
          description = "User not found"
          )
  @Operation(
    summary = "Delete user",
    description = "This can only be done by the logged in user.",
    operationId = "deleteUser")
public Response deleteUser(
    @Parameter(
        name = "username",
        description = "The name that needs to be deleted",
        schema = @Schema(type = SchemaType.STRING),
        required = true
        )
    @PathParam("username") String userName) {
        if (userData.removeUser(userName)) {
            return Response.ok().entity("").build();
        }
        else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    }
 
Example 7
Source File: VisibleOperationResource.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@GET
@Produces(MediaType.TEXT_PLAIN)
@Operation
@APIResponse(responseCode = "200", description = "A successful response", content = @Content(schema = @Schema(type = SchemaType.STRING)))
public String getPublicResponse() {
    return "response value";
}
 
Example 8
Source File: ParameterResource.java    From smallrye-open-api with 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 9
Source File: GetAuthor.java    From openshift-on-ibm-cloud-workshops with Apache License 2.0 5 votes vote down vote up
@GET
@APIResponses(value = {
	@APIResponse(
      responseCode = "404",
      description = "Author Not Found"
    ),
    @APIResponse(
      responseCode = "200",
      description = "Author with requested name",
      content = @Content(
        mediaType = "application/json",
        schema = @Schema(implementation = Author.class)
      )
    ),
    @APIResponse(
      responseCode = "500",
      description = "Internal service error"  	      
    )
})
@Operation(
	    summary = "Get specific author",
	    description = "Get specific author"
)
public Response getAuthor(@Parameter(
           description = "The unique name of the author",
           required = true,
           example = "Niklas Heidloff",
           schema = @Schema(type = SchemaType.STRING))
		@QueryParam("name") String name) {
			
		System.out.println("com.ibm.authors.GetAuthor.getAuthor /getauthor invoked");
	
		Author author = new Author();
		author.name = "Niklas Heidloff";
		author.twitter = "https://twitter.com/nheidloff";
		author.blog = "http://heidloff.net";

		return Response.ok(this.createJson(author)).build();
}
 
Example 10
Source File: ReviewResource.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@GET
@Path("{id}")
@APIResponse(
        responseCode="200",
        description="Review retrieved",
        content=@Content(
            schema=@Schema(
                implementation=Review.class)),
        headers = {
                @Header(
                    name = "responseHeader1",
                    description = "Max rate", 
                    schema = @Schema(type = SchemaType.INTEGER), 
                    required = true, 
                    allowEmptyValue = true, 
                    deprecated = true),
                @Header(
                    name = "responseHeader2",
                    description = "Input value", 
                    schema = @Schema(type = SchemaType.STRING), 
                    required = true, 
                    allowEmptyValue = true, 
                    deprecated = true
                )
        })
@APIResponse(
        responseCode="404",
        description="Review not found")
@Operation(
    operationId = "getReviewById",
    summary="Get a review with ID"
)
@Produces("application/json")
public Response getReviewById(
        @Parameter(
            name = "id",
            description = "ID of the booking",
            required = true,
            in = ParameterIn.PATH,
            content = @Content(
                examples = @ExampleObject(
                    name = "example",
                    value = "1")))
        @PathParam("id") int id){
    Review review = reviews.get(id);
    if(review!=null){
        return Response.ok().entity(review).build();
    }
    else{
        return Response.status(Status.NOT_FOUND).build();
    }
}
 
Example 11
Source File: ReviewResource.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@POST
@Callbacks(
    {@Callback(
        name = "testCallback",
        callbackUrlExpression="http://localhost:9080/oas3-airlines/reviews",
        operations = @CallbackOperation(
            summary = "Get all reviews",
            method = "get",
            responses = @APIResponse(
                responseCode = "200",
                description = "successful operation",
                content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(
                        type = SchemaType.ARRAY,
                        implementation = Review.class
                        )
                    )
                )
            )
        )
    }
)
@Tag(ref="Reviews")
@Servers(value={
        @Server(url = "localhost:9080/{proxyPath}/reviews/id",
                description = "view of all the reviews",
                variables = { @ServerVariable(name = "proxyPath", description = "Base path of the proxy", defaultValue = "proxy") }),
        @Server(url = "http://random.url/reviews", description = "random text")
})
@SecurityRequirement(
        name = "reviewoauth2",
        scopes = "write:reviews")
@APIResponse(
        responseCode="201",
        description="review created",
        content = @Content(
                schema = @Schema(
                        name= "id",
                        description = "id of the new review",
                        type = SchemaType.STRING)),
        links = {
                @Link(
                        name="Review",
                        description="get the review that was added",
                        operationId="getReviewById",
                        server = @Server(
                                description = "endpoint for all the review related methods",
                                url = "http://localhost:9080/airlines/reviews/"),
                                parameters = @LinkParameter(
                                        name = "reviewId",
                                        expression = "$request.path.id")
                        )
        }
        )
@RequestBody(
        ref = "#/components/requestBodies/review"
)
@Operation(
    summary="Create a Review",
    operationId = "createReview"
)
@Consumes("application/json")
@Produces("application/json")
public Response createReview(Review review) {
    reviews.put(currentId, review);
    return Response.status(Status.CREATED).entity("{\"id\":" + currentId++ + "}").build();
}
 
Example 12
Source File: UserResource.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@Path("/{username}")
  @PUT
  @RequestBody(
          name = "user",
          description = "Record of a new user to be created in the system.",
          content = @Content(
              mediaType = "application/json",
              schema = @Schema(implementation = User.class),
              examples = @ExampleObject(
                  name = "user",
                  summary = "Example user properties to update",
                  value = "Properties to update in JSON format here"
              )
          )
      )
  @Operation(
    summary = "Update user",
    description = "This can only be done by the logged in user.",
    operationId = "updateUser")
@APIResponses(value={
        @APIResponse(
                responseCode = "200",
                description = "User updated successfully",
                content = @Content(
                    schema = @Schema(ref="User"),
                    encoding = @Encoding(
                        name = "password",
                        contentType = "text/plain",
                        style = "form",
                        allowReserved = true,
                        explode = true,
                        headers = @Header(ref="Max-Rate")
                        )
                    )
            ),
            @APIResponse(
                responseCode = "400",
                description = "Invalid user supplied"
            ),
            @APIResponse(
                responseCode = "404",
                description = "User not found"
            )
})
@Tag(ref="user")
public Response updateUser(
    @Parameter(
        name = "username",
        description = "User that needs to be updated",
        schema = @Schema(type = SchemaType.STRING),
        required = true
        )
    @PathParam("username") String username,
    User user) {
            userData.addUser(user);
            return Response.ok().entity("").build();
        }
 
Example 13
Source File: UserResource.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@PATCH
@Path("/{username}")
@APIResponse(
        responseCode = "200",
        description = "Password was changed successfully"
    )
@Operation(
    summary = "Change user password",
    description = "This changes the password for the logged in user.",
    operationId = "changePassword"
)
@SecurityRequirementsSet(
    value = {
        @SecurityRequirement(
            name = "userApiKey"
        ),
        @SecurityRequirement(
            name = "userBearerHttp"
        )
    }
)
public void changePassword(
    @Parameter(
        name = "username",
        description = "name that need to be deleted",
        schema = @Schema(type = SchemaType.STRING),
        required = true)
    @PathParam("username") String username,
    @Parameter(
        name = "currentPassword",
        description = "the user's current password",
        schema = @Schema(type = SchemaType.STRING),
        required = true)
    @QueryParam("currentPassword") String currentPassword,
    @Parameter(
        name = "newPassword",
        description = "the user's desired new password",
        schema = @Schema(type = SchemaType.STRING),
        required = true)
    @QueryParam("newPassword") String newPassword) {
        // don't do anything - this is just a TCK test
}
 
Example 14
Source File: BookingResource.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@POST
@SecurityRequirement(
        name = "bookingSecurityScheme",
        scopes = {"write:bookings", "read:bookings"}
    )
@Callback(
    name = "bookingCallback",
    callbackUrlExpression = "http://localhost:9080/airlines/bookings",
    operations = @CallbackOperation(
        method ="get",
        summary="Retrieve all bookings for current user",
        responses={
            @APIResponse(
                responseCode="200",
                description="Bookings retrieved",
                content=@Content(
                    mediaType="application/json",
                    schema=@Schema(
                        type = SchemaType.ARRAY,
                        implementation=Booking.class))
            ),
            @APIResponse(
                responseCode="404",
                description="No bookings found for the user.")
        }))
@APIResponse(
        responseCode="201",
        description="Booking created",
        content = @Content(
            schema=@Schema(
                name= "id",
                description = "id of the new booking",
                type=SchemaType.STRING
            )
        )
    )
@Operation(
    summary="Create a booking",
    description = "Create a new booking record with the booking information provided.",
    operationId = "createBooking"
)
@Consumes("application/json")
@Produces("application/json")
public Response createBooking(@RequestBody(
        description = "Create a new booking with the provided information.",
        content = @Content(
            mediaType = "application/json",
            schema = @Schema(ref="Booking"),
            examples = @ExampleObject(
                name = "booking",
                summary = "External booking example",
                externalValue = "http://foo.bar/examples/booking-example.json"
            )
        )) Booking task) {
        bookings.put(currentId, task);
        return Response.status(Status.CREATED).entity("{\"id\":" + currentId++ + "}").build();
    }
 
Example 15
Source File: ResourceParameterTests.java    From smallrye-open-api with Apache License 2.0 4 votes vote down vote up
@Operation(summary = "Return all policies for a given account")
@GET
@Path("/")
@Parameters({
        @Parameter(name = "offset", in = ParameterIn.QUERY, description = "Page number, starts 0, if not specified uses 0.", schema = @Schema(type = SchemaType.INTEGER)),
        @Parameter(name = "limit", in = ParameterIn.QUERY, description = "Number of items per page, if not specified uses 10. "
                + "NO_LIMIT can be used to specify an unlimited page, when specified it ignores the offset", schema = @Schema(type = SchemaType.INTEGER)),
        @Parameter(name = "sortColumn", in = ParameterIn.QUERY, description = "Column to sort the results by", schema = @Schema(type = SchemaType.STRING, enumeration = {
                "name",
                "description",
                "is_enabled",
                "mtime"
        })),
        @Parameter(name = "sortDirection", in = ParameterIn.QUERY, description = "Sort direction used", schema = @Schema(type = SchemaType.STRING, enumeration = {
                "asc",
                "desc"
        })),
        @Parameter(name = "filter[name]", in = ParameterIn.QUERY, description = "Filtering policies by the name depending on the Filter operator used.", schema = @Schema(type = SchemaType.STRING)),
        @Parameter(name = "filter:op[name]", in = ParameterIn.QUERY, description = "Operations used with the filter", schema = @Schema(type = SchemaType.STRING, enumeration = {
                "equal",
                "like",
                "ilike",
                "not_equal"
        }, defaultValue = "equal")),
        @Parameter(name = "filter[description]", in = ParameterIn.QUERY, description = "Filtering policies by the description depending on the Filter operator used.", schema = @Schema(type = SchemaType.STRING)),
        @Parameter(name = "filter:op[description]", in = ParameterIn.QUERY, description = "Operations used with the filter", schema = @Schema(type = SchemaType.STRING, enumeration = {
                "equal",
                "like",
                "ilike",
                "not_equal"
        }, defaultValue = "equal")),
        @Parameter(name = "filter[is_enabled]", in = ParameterIn.QUERY, description = "Filtering policies by the is_enabled field."
                +
                "Defaults to true if no operand is given.", schema = @Schema(type = SchemaType.STRING, defaultValue = "true", enumeration = {
                        "true", "false" })),
})
@APIResponse(responseCode = "400", description = "Bad parameter for sorting was passed")
@APIResponse(responseCode = "404", description = "No policies found for customer")
@APIResponse(responseCode = "403", description = "Individual permissions missing to complete action")
@APIResponse(responseCode = "200", description = "Policies found", content = @Content(schema = @Schema(implementation = PagedResponse.class)), headers = @Header(name = "TotalCount", description = "Total number of items found", schema = @Schema(type = SchemaType.INTEGER)))
public Response getPoliciesForCustomer() {
    return null;
}
 
Example 16
Source File: UserResource.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@GET
@Path("/login")
@Tag()
@ExternalDocumentation(
        description = "Policy on user security.",
        url = "http://exampleurl.com/policy"
)
@APIResponse(
        responseCode = "200",
        description = "Successful user login.",
        content = @Content(
            schema = @Schema(implementation = User.class)
        )
    )
@APIResponse(
        responseCode = "400",
        description = "Invalid username/password supplied"
        )
@Operation(
    summary = "Logs user into the system",
    operationId = "logInUser"
)

@SecurityScheme(
    ref = "#/components/securitySchemes/httpTestScheme"
)
@SecurityRequirement(
    name = "httpTestScheme"
)
public Response loginUser(
    @Parameter(
        name = "username",
        description = "The user name for login",
        schema = @Schema(type = SchemaType.STRING),
        required = true
        )
    @QueryParam("username") String username,
    @Parameter(
        name = "password",
        description = "The password for login in clear text",
        schema = @Schema(type = SchemaType.STRING),
        required = true)
    @QueryParam("password") String password) {
        return Response.ok()
            .entity("logged in user session:" + System.currentTimeMillis())
            .build();
    }
 
Example 17
Source File: PetResource.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@DELETE
@Path("/{petId}")
@SecurityRequirement(
        name = "petsOAuth2",
        scopes = "write:pets"
        )
@APIResponses(value = {
        @APIResponse(
                responseCode = "400",
                description = "Invalid ID supplied"
            ),
            @APIResponse(
                responseCode = "404",
                description = "Pet not found"
            )
})
@Operation(
    summary = "Deletes a pet by ID",
    description = "Returns a pet when ID is less than or equal to 10"
)
public Response deletePet(
    @Parameter(
        name = "apiKey",
        description = "authentication key to access this method",
        schema = @Schema(type = SchemaType.STRING, implementation = String.class,
          maxLength = 256, minLength = 32))
    @HeaderParam("api_key") String apiKey,
    @Parameter(
        name = "petId",
        description = "ID of pet that needs to be fetched",
        required = true,
        schema = @Schema(
            implementation = Long.class,
            maximum = "10",
            minimum = "1"))
    @PathParam("petId") Long petId) {
        if (petData.deletePet(petId)) {
            return Response.ok().build();
        }
        else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    }
 
Example 18
Source File: UserResource.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@GET
@Path("/{username}")
@APIResponses(value={
        @APIResponse(
                responseCode = "200",
                description = "successful operation",
                content = @Content(
                    schema = @Schema(implementation = User.class)
                )
            ),
        @APIResponse(
                responseCode = "400",
                description = "Invalid username supplied",
                content = @Content(
                    schema = @Schema(implementation = User.class)
                )
            ),
        @APIResponse(
                responseCode = "404",
                description = "User not found",
                content = @Content(
                    schema = @Schema(implementation = User.class)
                )
            )
})
@Operation(
    summary = "Get user by user name"
)
public Response getUserByName(
    @Parameter(
        name = "username",
        description = "The name that needs to be fetched. Use user1 for testing.",
        schema = @Schema(type = SchemaType.STRING),
        required = true
    )
    @PathParam("username") String username) throws ApiException {
        User user = userData.findUserByName(username);
        if (null != user) {
            return Response.ok().entity(user).build();
        }
        else {
            throw new NotFoundException(404, "User not found");
        }
    }