Skip to content

Commit b6a0778

Browse files
MikeEdgarAzquelt
andauthored
TCK: fix several incorrectly used annotations and associated tests (#562)
* TCK: fix several incorrectly used annotations and associated tests * Align link parameter name with operation's path parameter name * Remove `/findByStatus` endpoint Signed-off-by: Michael Edgar <[email protected]> Co-authored-by: Andrew Rouse <[email protected]>
1 parent cb879f5 commit b6a0778

File tree

10 files changed

+31
-69
lines changed

10 files changed

+31
-69
lines changed

tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/JAXRSApp.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
extensions = @Extension(name = "x-external-docs",
7272
value = "test-external-docs")),
7373
info = @Info(title = "AirlinesRatingApp API", version = "1.0",
74+
description = "APIs for booking and managing air flights",
7475
termsOfService = "http://airlinesratingapp.com/terms",
7576
contact = @Contact(name = "AirlinesRatingApp API Support",
7677
url = "http://exampleurl.com/contact",
@@ -208,10 +209,6 @@
208209
@SecurityScheme(securitySchemeName = "testScheme2",
209210
type = SecuritySchemeType.HTTP,
210211
scheme = "Basic")
211-
@Schema(name = "AirlinesRatingApp API",
212-
description = "APIs for booking and managing air flights",
213-
externalDocs = @ExternalDocumentation(description = "For more information, see the link.",
214-
url = "http://exampleurl.com/schema"))
215212
public class JAXRSApp extends Application {
216213
@Override
217214
public Set<Object> getSingletons() {

tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/model/User.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class User {
3333
@Schema(required = true, example = "Smith")
3434
private String lastName;
3535

36-
@Schema(required = true, example = "M")
36+
@Schema(required = true, example = "Male")
3737
private Gender gender;
3838

3939
@Schema(required = true, example = "37")

tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/resources/AirlinesResource.java

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import jakarta.ws.rs.core.Response;
3838

3939
@Path("")
40-
@Schema(name = "Airline Booking API")
4140
@Tags(value = @Tag(name = "Airlines", description = "All the airlines methods"))
4241
@Callback(name = "availabilityCallback", callbackUrlExpression = "http://localhost:9080/oas3-airlines/availability",
4342
operations = @CallbackOperation(method = "get", summary = "Retrieve available flights.", responses = {

tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/resources/ReviewResource.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,8 @@ public Response getReviewById(
161161
@Produces("application/json")
162162
public Response getReviewByUser(
163163
@Parameter(name = "user", description = "username of the user for the reviews", in = ParameterIn.PATH,
164-
content = @Content(examples = @ExampleObject(name = "example", value = "bsmith")), examples = {
165-
@ExampleObject(name = "example1", value = "bsmith"),
166-
@ExampleObject(name = "example2",
167-
value = "[email protected]")}) @PathParam("user") String user,
164+
content = @Content(examples = {
165+
@ExampleObject(name = "example", value = "bsmith")})) @PathParam("user") String user,
168166
@QueryParam("minRating") Integer minRating,
169167
@HeaderParam("If-Match") String ifMatch,
170168
@CookieParam("trackme") String trackme) {
@@ -201,8 +199,7 @@ public Response getReviewByUser(
201199
@Operation(operationId = "getReviewByAirline", summary = "Get all reviews by airlines")
202200
@Parameter(name = "airline", description = "name of the airlines for the reviews", required = true,
203201
in = ParameterIn.PATH,
204-
content = @Content(examples = @ExampleObject(name = "example", value = "Acme Air")),
205-
example = "Acme Air")
202+
content = @Content(examples = @ExampleObject(name = "example", value = "Acme Air")))
206203
@APIResponse(responseCode = "200", description = "Review(s) retrieved",
207204
content = @Content(schema = @Schema(implementation = Review.class)))
208205
@APIResponse(responseCode = "404", description = "Review(s) not found")

tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/resources/UserResource.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,7 @@ public Response createUsersWithArrayInput(
152152
content = @Content(mediaType = "application/json",
153153
schema = @Schema(type = SchemaType.ARRAY, implementation = User.class,
154154
nullable = true, writeOnly = true, minItems = 2,
155-
maxItems = 20, uniqueItems = true),
156-
encoding = @Encoding(name = "firstName", contentType = "text/plain",
157-
style = "form", allowReserved = true,
158-
explode = true))) User[] users) {
155+
maxItems = 20, uniqueItems = true))) User[] users) {
159156
for (User user : users) {
160157
userData.addUser(user);
161158
}
@@ -279,8 +276,8 @@ public Response getUserByName(
279276
parameters = @LinkParameter(name = "userId", expression = "$request.path.id"),
280277
extensions = @Extension(name = "x-link", value = "test-link")),
281278
@Link(name = "Review", description = "The reviews provided by user",
282-
operationRef = "/db/reviews/{userName}",
283-
parameters = @LinkParameter(name = "path.userName",
279+
operationRef = "#/paths/~1reviews~1users~1{user}/get",
280+
parameters = @LinkParameter(name = "path.user",
284281
expression = "$response.body#userName"),
285282
requestBody = "$request.path.id", server = @Server(url = "http://example.com"))
286283
})

tck/src/main/java/org/eclipse/microprofile/openapi/apps/petstore/resource/PetResource.java

+10-33
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
2323
import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeIn;
2424
import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeType;
25-
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
26-
import org.eclipse.microprofile.openapi.annotations.extensions.Extensions;
2725
import org.eclipse.microprofile.openapi.annotations.media.Content;
2826
import org.eclipse.microprofile.openapi.annotations.media.ExampleObject;
2927
import org.eclipse.microprofile.openapi.annotations.media.Schema;
@@ -62,16 +60,17 @@
6260
import jakarta.ws.rs.core.StreamingOutput;
6361

6462
@Path("/pet")
65-
@Schema(name = "pet", description = "Operations on pets resource")
6663
@SecuritySchemes(value = {
6764
@SecurityScheme(securitySchemeName = "petsApiKey", type = SecuritySchemeType.APIKEY,
6865
description = "authentication needed to create a new pet profile for the store",
6966
apiKeyName = "createPetProfile", in = SecuritySchemeIn.HEADER),
7067
@SecurityScheme(securitySchemeName = "petsOAuth2", type = SecuritySchemeType.OAUTH2,
7168
description = "authentication needed to delete a pet profile",
72-
flows = @OAuthFlows(implicit = @OAuthFlow(authorizationUrl = "https://example.com/api/oauth/dialog"),
69+
flows = @OAuthFlows(implicit = @OAuthFlow(authorizationUrl = "https://example.com/api/oauth/dialog",
70+
scopes = {}),
7371
authorizationCode = @OAuthFlow(authorizationUrl = "https://example.com/api/oauth/dialog",
74-
tokenUrl = "https://example.com/api/oauth/token"))),
72+
tokenUrl = "https://example.com/api/oauth/token",
73+
scopes = {}))),
7574
@SecurityScheme(securitySchemeName = "petsHttp", type = SecuritySchemeType.HTTP,
7675
description = "authentication needed to update an exsiting record of a pet in the store",
7776
scheme = "bearer", bearerFormat = "jwt")
@@ -87,6 +86,7 @@ public class PetResource {
8786
content = @Content(mediaType = "none")),
8887
@APIResponse(responseCode = "404", description = "Pet not found", content = @Content(mediaType = "none")),
8988
@APIResponse(responseCode = "200",
89+
description = "Pet found",
9090
content = @Content(mediaType = "application/json",
9191
schema = @Schema(type = SchemaType.OBJECT, implementation = Pet.class,
9292
oneOf = {
@@ -150,7 +150,7 @@ public void write(OutputStream output) throws IOException {
150150
public Response deletePet(
151151
@Parameter(name = "apiKey", description = "authentication key to access this method",
152152
schema = @Schema(type = SchemaType.STRING, implementation = String.class, maxLength = 256,
153-
minLength = 32)) @HeaderParam("api_key") String apiKey,
153+
minLength = 32)) @HeaderParam("apiKey") String apiKey,
154154
@Parameter(name = "petId", description = "ID of pet that needs to be fetched", required = true,
155155
schema = @Schema(implementation = Long.class, maximum = "10",
156156
minimum = "1")) @PathParam("petId") Long petId) {
@@ -191,37 +191,13 @@ public Response addPet(Pet pet) {
191191
})
192192
@Operation(summary = "Update an existing pet", description = "Update an existing pet with the given new attributes")
193193
public Response updatePet(
194-
@Parameter(name = "petAttribute", description = "Attribute to update existing pet record", required = true,
195-
schema = @Schema(implementation = Pet.class)) Pet pet) {
194+
@RequestBody(description = "Attribute to update existing pet record",
195+
required = true,
196+
content = @Content(schema = @Schema(implementation = Pet.class))) Pet pet) {
196197
Pet updatedPet = petData.addPet(pet);
197198
return Response.ok().entity(updatedPet).build();
198199
}
199200

200-
@GET
201-
@Path("/findByStatus")
202-
@APIResponse(responseCode = "400", description = "Invalid status value", content = @Content(mediaType = "none"))
203-
@APIResponse(responseCode = "200",
204-
content = @Content(mediaType = "application/json",
205-
schema = @Schema(type = SchemaType.ARRAY, implementation = Pet.class)))
206-
@Operation(summary = "Finds Pets by status",
207-
description = "Find all the Pets with the given status; Multiple status values can be provided with comma seperated strings")
208-
@Extension(name = "x-mp-method1", value = "true")
209-
@Extensions({@Extension(name = "x-mp-method2", value = "true"), @Extension(value = "false", name = "x-mp-method3")})
210-
public Response findPetsByStatus(
211-
@Parameter(name = "status", description = "Status values that need to be considered for filter",
212-
required = true, schema = @Schema(implementation = String.class), content = {
213-
@Content(examples = {
214-
@ExampleObject(name = "Available", value = "available",
215-
summary = "Retrieves all the pets that are available"),
216-
@ExampleObject(name = "Pending", value = "pending",
217-
summary = "Retrieves all the pets that are pending to be sold"),
218-
@ExampleObject(name = "Sold", value = "sold",
219-
summary = "Retrieves all the pets that are sold")
220-
})
221-
}, allowEmptyValue = true) @Extension(name = "x-mp-parm1", value = "true") String status) {
222-
return Response.ok(petData.findPetByStatus(status)).build();
223-
}
224-
225201
@GET
226202
@Path("/findByTags")
227203
@Produces("application/json")
@@ -233,6 +209,7 @@ public Response findPetsByStatus(
233209
description = "Invalid tag value",
234210
content = @Content(mediaType = "none")),
235211
@APIResponse(responseCode = "200",
212+
description = "Pet callback successfully processed",
236213
content = @Content(mediaType = "application/json",
237214
schema = @Schema(type = SchemaType.ARRAY,
238215
implementation = Pet.class)))

tck/src/main/java/org/eclipse/microprofile/openapi/apps/petstore/resource/PetStoreResource.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.eclipse.microprofile.openapi.annotations.media.DiscriminatorMapping;
2222
import org.eclipse.microprofile.openapi.annotations.media.Schema;
2323
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
24+
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
2425
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
2526
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
2627
import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement;
@@ -43,7 +44,6 @@
4344
import jakarta.ws.rs.core.Response;
4445

4546
@Path("/store")
46-
@Schema(name = "/store")
4747
@Produces({"application/json", "application/xml"})
4848
@SecuritySchemes(value = {
4949
@SecurityScheme(securitySchemeName = "storeOpenIdConnect", type = SecuritySchemeType.OPENIDCONNECT,
@@ -94,7 +94,7 @@ public java.util.Map<String, Integer> getInventory() {
9494
BadOrder.class}, discriminatorProperty = "id",
9595
discriminatorMapping = @DiscriminatorMapping(value = "0",
9696
schema = BadOrder.class))))
97-
@APIResponse(responseCode = "900", description = "Invalid",
97+
@APIResponse(responseCode = "599", description = "Invalid",
9898
content = @Content(schema = @Schema(implementation = Order.class, hidden = true)))
9999
public Response getOrderById(
100100
@Parameter(name = "orderId", description = "ID of pet that needs to be fetched",
@@ -115,7 +115,7 @@ public Response getOrderById(
115115
@APIResponse(responseCode = "200", description = "successful operation")
116116
@APIResponse(responseCode = "400", description = "Invalid Order")
117117
public Order placeOrder(
118-
@Parameter(description = "order placed for purchasing the pet", required = true) Order order) {
118+
@RequestBody(description = "order placed for purchasing the pet", required = true) Order order) {
119119
storeData.placeOrder(order);
120120
return storeData.placeOrder(order);
121121
}

tck/src/main/java/org/eclipse/microprofile/openapi/apps/petstore/resource/UserResource.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.eclipse.microprofile.openapi.annotations.media.Content;
2121
import org.eclipse.microprofile.openapi.annotations.media.Schema;
2222
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
23+
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
2324
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
2425
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
2526
import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement;
@@ -43,7 +44,6 @@
4344
import jakarta.ws.rs.core.Response;
4445

4546
@Path("/user")
46-
@Schema(name = "/user")
4747
@Produces({"application/json", "application/xml"})
4848
@SecuritySchemes(value = {
4949
@SecurityScheme(securitySchemeName = "userApiKey", type = SecuritySchemeType.APIKEY,
@@ -68,8 +68,9 @@ public class UserResource {
6868
@SecurityRequirement(name = "userBearerHttp")
6969
})
7070
public Response createUser(
71-
@Parameter(description = "Created user object", schema = @Schema(ref = "#/components/schemas/User"),
72-
required = true) User user) {
71+
@RequestBody(description = "Created user object",
72+
content = @Content(schema = @Schema(ref = "#/components/schemas/User")),
73+
required = true) User user) {
7374
userData.addUser(user);
7475
return Response.ok().entity("").build();
7576
}
@@ -79,7 +80,7 @@ public Response createUser(
7980
@APIResponse(description = "successful operation")
8081
@Operation(summary = "Creates list of users with given input array")
8182
public Response createUsersWithArrayInput(
82-
@Parameter(description = "List of user object", required = true) User[] users) {
83+
@RequestBody(description = "List of user object", required = true) User[] users) {
8384
for (User user : users) {
8485
userData.addUser(user);
8586
}
@@ -91,7 +92,7 @@ public Response createUsersWithArrayInput(
9192
@APIResponse(description = "successful operation")
9293
@Operation(summary = "Creates list of users with given input array")
9394
public Response createUsersWithListInput(
94-
@Parameter(description = "List of user object", required = true) java.util.List<User> users) {
95+
@RequestBody(description = "List of user object", required = true) java.util.List<User> users) {
9596
for (User user : users) {
9697
userData.addUser(user);
9798
}
@@ -111,7 +112,7 @@ public Response updateUser(
111112
@Parameter(name = "username", description = "name that need to be deleted",
112113
schema = @Schema(type = SchemaType.STRING),
113114
required = true) @PathParam("username") String username,
114-
@Parameter(description = "Updated user object", required = true) User user) {
115+
@RequestBody(description = "Updated user object", required = true) User user) {
115116
userData.addUser(user);
116117
return Response.ok().entity("").build();
117118
}

tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ public void testLink(String type) {
671671
vr.body(s + "x-link", equalTo("test-link"));
672672

673673
String t = "paths.'/user/id/{id}'.get.responses.'200'.links.Review.";
674-
vr.body(t + "operationRef", equalTo("/db/reviews/{userName}"));
674+
vr.body(t + "operationRef", equalTo("#/paths/~1reviews~1users~1{user}/get"));
675675
vr.body(t + "description", equalTo("The reviews provided by user"));
676676

677677
String k = "paths.'/reviews'.post.responses.'201'.links.Review.";
@@ -686,7 +686,7 @@ public void testLinkParameter(String type) {
686686
vr.body(s + "parameters.userId", equalTo("$request.path.id"));
687687

688688
String t = "paths.'/user/id/{id}'.get.responses.'200'.links.Review.";
689-
vr.body(t + "parameters.'path.userName'", equalTo("$response.body#userName"));
689+
vr.body(t + "parameters.'path.user'", equalTo("$response.body#userName"));
690690

691691
String k = "paths.'/reviews'.post.responses.'201'.links.Review.";
692692
vr.body(k + "parameters.reviewId", equalTo("$request.path.id"));
@@ -752,12 +752,6 @@ public void testExampleObject(String type) {
752752
// Example in Parameter Content
753753
vr.body("paths.'/reviews/users/{user}'.get.parameters.find{ it.name=='user'}.content.'*/*'.examples.example.value",
754754
equalTo("bsmith"));
755-
756-
// Example in Parameter
757-
vr.body("paths.'/reviews/users/{user}'.get.parameters.find{ it.name=='user'}.examples.example1.value",
758-
equalTo("bsmith"));
759-
vr.body("paths.'/reviews/users/{user}'.get.parameters.find{ it.name=='user'}.examples.example2.value",
760-
equalTo("[email protected]"));
761755
}
762756

763757
@Test(dataProvider = "formatProvider")

tck/src/main/java/org/eclipse/microprofile/openapi/tck/PetStoreAppTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void testSchema(String type) {
5757
vr.body("paths.'/pet/findByTags'.get.parameters.find{ it.name == 'tags' }.schema.externalDocs.description",
5858
equalTo("Pet Types"));
5959
vr.body("paths.'/pet/findByTags'.get.parameters.find{ it.name == 'tags' }.schema.deprecated", equalTo(true));
60-
vr.body("paths.'/store/order/{orderId}'.get.responses.'900'.schema", nullValue());
60+
vr.body("paths.'/store/order/{orderId}'.get.responses.'599'.schema", nullValue());
6161

6262
// Numerical properties
6363
vr.body("paths.'/pet/{petId}'.get.parameters.find{ it.name == 'petId' }.schema.maximum",

0 commit comments

Comments
 (0)