Skip to content

Commit c3592a6

Browse files
committed
Add comprehensive annotation extension tests
Make sure the TCK exercises the extensions attribute on every annotation which has one.
1 parent 938bfa7 commit c3592a6

File tree

6 files changed

+94
-20
lines changed

6 files changed

+94
-20
lines changed

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

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
2727
import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeIn;
2828
import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeType;
29+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
2930
import org.eclipse.microprofile.openapi.annotations.headers.Header;
3031
import org.eclipse.microprofile.openapi.annotations.info.Contact;
3132
import org.eclipse.microprofile.openapi.annotations.info.Info;
@@ -63,16 +64,24 @@
6364
@OpenAPIDefinition(
6465
tags = {@Tag(name = "user", description = "Operations about user"),
6566
@Tag(name = "create", description = "Operations about create"),
66-
@Tag(name = "Bookings", description = "All the bookings methods")},
67+
@Tag(name = "Bookings", description = "All the bookings methods",
68+
extensions = @Extension(name = "x-tag", value = "test-tag"))},
6769
externalDocs = @ExternalDocumentation(description = "instructions for how to deploy this app",
68-
url = "https://github.com/microservices-api/oas3-airlines/blob/master/README.md"),
70+
url = "https://github.com/microservices-api/oas3-airlines/blob/master/README.md",
71+
extensions = @Extension(name = "x-external-docs",
72+
value = "test-external-docs")),
6973
info = @Info(title = "AirlinesRatingApp API", version = "1.0",
7074
termsOfService = "http://airlinesratingapp.com/terms",
7175
contact = @Contact(name = "AirlinesRatingApp API Support",
7276
url = "http://exampleurl.com/contact",
73-
email = "[email protected]"),
77+
email = "[email protected]",
78+
extensions = @Extension(name = "x-contact", value = "test-contact")),
7479
license = @License(name = "Apache 2.0",
75-
url = "http://www.apache.org/licenses/LICENSE-2.0.html")),
80+
url = "http://www.apache.org/licenses/LICENSE-2.0.html",
81+
extensions = @Extension(name = "x-license", value = "test-license")),
82+
extensions = {@Extension(name = "x-info-1", value = "test-info-1"),
83+
@Extension(name = "x-info", value = "test-info")
84+
}),
7685
security = @SecurityRequirement(name = "airlinesRatingApp_auth"),
7786
securitySets = @SecurityRequirementsSet({
7887
@SecurityRequirement(name = "testScheme1"), @SecurityRequirement(name = "testScheme2")
@@ -88,9 +97,12 @@
8897
@ServerVariable(name = "port", description = "Booking data",
8998
defaultValue = "8443"),
9099
@ServerVariable(name = "user", description = "User data",
91-
defaultValue = "user"),
100+
defaultValue = "user",
101+
extensions = @Extension(name = "x-server-variable",
102+
value = "test-server-variable")),
92103
@ServerVariable(name = "basePath", defaultValue = "v2")
93-
}),
104+
},
105+
extensions = @Extension(name = "x-server", value = "test-server")),
94106
@Server(url = "https://test-server.com:80/basePath", description = "The test API server")
95107
},
96108
components = @Components(
@@ -100,14 +112,18 @@
100112
implementation = Booking.class),
101113
@Schema(name = "Airlines", title = "Airlines",
102114
type = SchemaType.ARRAY,
103-
implementation = Airline.class),
115+
implementation = Airline.class,
116+
extensions = @Extension(name = "x-schema",
117+
value = "test-schema")),
104118
@Schema(name = "id", type = SchemaType.INTEGER, format = "int32"),
105119
@Schema(name = "AirlinesRef",
106120
ref = "#/components/schemas/Airlines"),
107121
@Schema(name = "User", implementation = User.class, properties = {
108122
@SchemaProperty(name = "phone",
109123
description = "Telephone number to contact the user",
110-
example = "123-456-7891")
124+
example = "123-456-7891",
125+
extensions = @Extension(name = "x-schema-property",
126+
value = "test-schema-property"))
111127
})},
112128
responses = {
113129
@APIResponse(name = "FoundAirlines", responseCode = "200",
@@ -133,7 +149,9 @@
133149
examples = {
134150
@ExampleObject(name = "review", summary = "External review example",
135151
description = "This example exemplifies the content on our site.",
136-
externalValue = "http://foo.bar/examples/review-example.json"),
152+
externalValue = "http://foo.bar/examples/review-example.json",
153+
extensions = @Extension(name = "x-example-object",
154+
value = "test-example-object")),
137155
@ExampleObject(name = "user", summary = "External user example",
138156
externalValue = "http://foo.bar/examples/user-example.json")
139157
},
@@ -147,7 +165,9 @@
147165
@Header(name = "Max-Rate", description = "Maximum rate",
148166
schema = @Schema(type = SchemaType.INTEGER),
149167
required = true, allowEmptyValue = true,
150-
deprecated = true),
168+
deprecated = true,
169+
extensions = @Extension(name = "x-header",
170+
value = "test-header")),
151171
@Header(name = "Request-Limit",
152172
description = "The number of allowed requests in the current period",
153173
schema = @Schema(type = SchemaType.INTEGER))
@@ -172,12 +192,15 @@
172192
responses = {
173193
@APIResponse(ref = "FoundBookings")
174194
}))
175-
}))
195+
},
196+
extensions = @Extension(name = "x-components", value = "test-components")),
197+
extensions = @Extension(name = "x-openapi-definition", value = "test-openapi-definition"))
176198
@SecurityScheme(securitySchemeName = "airlinesRatingApp_auth",
177199
description = "authentication needed to access Airlines app",
178200
type = SecuritySchemeType.APIKEY,
179201
apiKeyName = "api_key",
180-
in = SecuritySchemeIn.HEADER)
202+
in = SecuritySchemeIn.HEADER,
203+
extensions = @Extension(name = "x-security-scheme", value = "test-security-scheme"))
181204
@SecurityScheme(securitySchemeName = "testScheme1",
182205
type = SecuritySchemeType.APIKEY,
183206
apiKeyName = "test1",

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.eclipse.microprofile.openapi.annotations.ExternalDocumentation;
2020
import org.eclipse.microprofile.openapi.annotations.Operation;
2121
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
22+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
2223
import org.eclipse.microprofile.openapi.annotations.media.Content;
2324
import org.eclipse.microprofile.openapi.annotations.media.Schema;
2425
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
@@ -44,15 +45,18 @@ public class AvailabilityResource {
4445
@Tag(ref = "Availability")
4546
@APIResponse(responseCode = "200", description = "successful operation",
4647
content = @Content(mediaType = "application/json",
47-
schema = @Schema(type = SchemaType.ARRAY, implementation = Flight.class)))
48+
schema = @Schema(type = SchemaType.ARRAY, implementation = Flight.class),
49+
extensions = @Extension(name = "x-content", value = "test-content")))
4850
@APIResponse(responseCode = "404", description = "No available flights found",
4951
content = @Content(mediaType = "n/a"))
50-
@Operation(summary = "Retrieve all available flights", operationId = "getFlights")
52+
@Operation(summary = "Retrieve all available flights", operationId = "getFlights",
53+
extensions = @Extension(name = "x-operation", value = "test-operation"))
5154
@Produces("application/json")
5255
public Response getFlights(
5356
@Parameter(ref = "#/components/parameters/departureDate") @QueryParam("departureDate") String departureDate,
5457
@Parameter(name = "airportFrom", required = true, allowEmptyValue = true,
5558
description = "Airport the customer departs from",
59+
extensions = @Extension(name = "x-parameter", value = "test-parameter"),
5660
schema = @Schema(implementation = String.class)) @QueryParam("airportFrom") String airportFrom,
5761
@Parameter(name = "returningDate", required = true, allowReserved = true,
5862
description = "Customer return date",

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.eclipse.microprofile.openapi.annotations.enums.ParameterIn;
2626
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
2727
import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeType;
28+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
2829
import org.eclipse.microprofile.openapi.annotations.headers.Header;
2930
import org.eclipse.microprofile.openapi.annotations.links.Link;
3031
import org.eclipse.microprofile.openapi.annotations.links.LinkParameter;
@@ -74,7 +75,9 @@
7475
description = "authentication needed to create and delete reviews",
7576
flows = @OAuthFlows(implicit = @OAuthFlow(authorizationUrl = "https://example.com/api/oauth/dialog",
7677
scopes = @OAuthScope(name = "write:reviews",
77-
description = "create a review")),
78+
description = "create a review"),
79+
extensions = @Extension(name = "x-oauth-flow",
80+
value = "test-oauth-flow")),
7881
authorizationCode = @OAuthFlow(authorizationUrl = "https://example.com/api/oauth/dialog",
7982
tokenUrl = "https://example.com/api/oauth/token",
8083
scopes = @OAuthScope(name = "read:reviews",
@@ -85,7 +88,8 @@
8588
description = "create a review")),
8689
clientCredentials = @OAuthFlow(tokenUrl = "https://example.com/api/oauth/token",
8790
scopes = @OAuthScope(name = "read:reviews",
88-
description = "search for a review"))))
91+
description = "search for a review")),
92+
extensions = @Extension(name = "x-oauth-flows", value = "test-oauth-flows")))
8993
@Tags(value = {
9094
@Tag(name = "Reviews", description = "All the review methods"),
9195
@Tag(name = "Ratings", description = "All the ratings methods")
@@ -262,7 +266,10 @@ public Response getReviewByAirlineAndUser(
262266
description = "successful operation",
263267
content = @Content(mediaType = "application/json",
264268
schema = @Schema(type = SchemaType.ARRAY,
265-
implementation = Review.class)))))
269+
implementation = Review.class))),
270+
extensions = @Extension(name = "x-callback-operation",
271+
value = "test-callback-operation")),
272+
extensions = @Extension(name = "x-callback", value = "test-callback"))
266273
})
267274
@Tag(ref = "Reviews")
268275
@Servers(value = {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.eclipse.microprofile.openapi.annotations.enums.ParameterStyle;
2020
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
2121
import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeType;
22+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
2223
import org.eclipse.microprofile.openapi.annotations.headers.Header;
2324
import org.eclipse.microprofile.openapi.annotations.links.Link;
2425
import org.eclipse.microprofile.openapi.annotations.links.LinkParameter;
@@ -129,7 +130,9 @@ public Response createUser(
129130
schema = @Schema(type = SchemaType.INTEGER),
130131
required = true,
131132
allowEmptyValue = true,
132-
deprecated = true)))) User user) {
133+
deprecated = true),
134+
extensions = @Extension(name = "x-encoding",
135+
value = "test-encoding")))) User user) {
133136
userData.addUser(user);
134137
return Response.ok().entity("").build();
135138
}
@@ -273,7 +276,8 @@ public Response getUserByName(
273276
content = @Content(schema = @Schema(implementation = User.class)), links = {
274277
@Link(name = "User name", description = "The username corresponding to provided user id",
275278
operationId = "getUserByName",
276-
parameters = @LinkParameter(name = "userId", expression = "$request.path.id")),
279+
parameters = @LinkParameter(name = "userId", expression = "$request.path.id"),
280+
extensions = @Extension(name = "x-link", value = "test-link")),
277281
@Link(name = "Review", description = "The reviews provided by user",
278282
operationRef = "/db/reviews/{userName}",
279283
parameters = @LinkParameter(name = "path.userName",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.eclipse.microprofile.openapi.annotations.enums.ParameterStyle;
2424
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
2525
import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeType;
26+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
2627
import org.eclipse.microprofile.openapi.annotations.media.Content;
2728
import org.eclipse.microprofile.openapi.annotations.media.ExampleObject;
2829
import org.eclipse.microprofile.openapi.annotations.media.Schema;
@@ -100,7 +101,8 @@ public Response createBooking(
100101
content = @Content(mediaType = "application/json", schema = @Schema(ref = "Booking"),
101102
examples = @ExampleObject(name = "booking",
102103
summary = "External booking example",
103-
externalValue = "http://foo.bar/examples/booking-example.json"))) Booking task) {
104+
externalValue = "http://foo.bar/examples/booking-example.json")),
105+
extensions = @Extension(name = "x-request-body", value = "test-request-body")) Booking task) {
104106
bookings.put(currentId, task);
105107
return Response.status(Status.CREATED).entity("{\"id\":" + currentId++ + "}").build();
106108
}

0 commit comments

Comments
 (0)