Skip to content
This repository was archived by the owner on Oct 30, 2023. It is now read-only.

Commit 733686c

Browse files
authored
Merge pull request #100 from swagger-api/samples-3.0
update deps versions and sample resources for openAPI 3.0
2 parents 7190751 + ce45fca commit 733686c

File tree

6 files changed

+77
-135
lines changed

6 files changed

+77
-135
lines changed

java/java-jersey2/pom.xml

+9-26
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,6 @@
3535
<groupId>org.eclipse.jetty</groupId>
3636
<artifactId>jetty-maven-plugin</artifactId>
3737
<version>${jetty-version}</version>
38-
<dependencies>
39-
<!--
40-
<dependency>
41-
<groupId>ch.qos.logback</groupId>
42-
<artifactId>logback-classic</artifactId>
43-
<version>${logback-version}</version>
44-
</dependency>
45-
-->
46-
<!--
47-
<dependency>
48-
<groupId>ch.qos.logback</groupId>
49-
<artifactId>logback-access</artifactId>
50-
<version>${logback-version}</version>
51-
</dependency>
52-
-->
53-
<!--
54-
<dependency>
55-
<groupId>org.slf4j</groupId>
56-
<artifactId>slf4j-api</artifactId>
57-
<version>${slf4j-version}</version>
58-
</dependency>
59-
-->
60-
</dependencies>
6138
<configuration>
6239
<webApp>
6340
<contextPath>/</contextPath>
@@ -165,7 +142,7 @@
165142
<dependency>
166143
<groupId>com.fasterxml.jackson.jaxrs</groupId>
167144
<artifactId>jackson-jaxrs-json-provider</artifactId>
168-
<version>2.8.9</version>
145+
<version>${jackson-version}</version>
169146
</dependency>
170147

171148
<dependency>
@@ -188,17 +165,23 @@
188165
</dependency>
189166
<dependency>
190167
<groupId>javax.servlet</groupId>
191-
<artifactId>servlet-api</artifactId>
168+
<artifactId>javax.servlet-api</artifactId>
169+
<scope>provided</scope>
192170
</dependency>
193171
<dependency>
194172
<groupId>org.glassfish.jersey.containers</groupId>
195-
<artifactId>jersey-container-servlet-core</artifactId>
173+
<artifactId>jersey-container-servlet</artifactId>
196174
<version>${jersey2-version}</version>
197175
</dependency>
198176
<dependency>
199177
<groupId>org.glassfish.jersey.media</groupId>
200178
<artifactId>jersey-media-multipart</artifactId>
201179
<version>${jersey2-version}</version>
202180
</dependency>
181+
<dependency>
182+
<groupId>org.glassfish.jersey.inject</groupId>
183+
<artifactId>jersey-hk2</artifactId>
184+
<version>${jersey2-version}</version>
185+
</dependency>
203186
</dependencies>
204187
</project>

java/java-jersey2/src/main/java/io/swagger/sample/resource/PetResource.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ public class PetResource {
5353
@ApiResponse(responseCode = "404", description = "Pet not found")
5454
})
5555
public Response getPetById(
56-
@Parameter(description = "ID of pet that needs to be fetched"/*, _enum = "range[1,10]"*/, required = true)
56+
@Parameter(
57+
description = "ID of pet that needs to be fetched",
58+
schema = @Schema(
59+
type = "integer",
60+
format = "int64",
61+
description = "param ID of pet that needs to be fetched",
62+
allowableValues = {"1","2","3"}
63+
),
64+
required = true)
5765
@PathParam("petId") Long petId) throws io.swagger.sample.exception.NotFoundException {
5866
Pet pet = petData.getPetById(petId);
5967
if (null != pet) {
@@ -103,7 +111,15 @@ public Response updatePet(
103111
)}
104112
)
105113
public Response findPetsByStatus(
106-
@Parameter(description = "Status values that need to be considered for filter", required = true/*, defaultValue = "available", allowableValues = "available,pending,sold", allowMultiple = true*/) @QueryParam("status") String status,
114+
@Parameter(
115+
description = "Status values that need to be considered for filter",
116+
required = true,
117+
schema = @Schema(
118+
allowableValues = {"available","pending","sold"},
119+
defaultValue = "available"
120+
)
121+
)
122+
@QueryParam("status") String status,
107123
@BeanParam QueryResultBean qr
108124
){
109125
return Response.ok(petData.findPetByStatus(status)).build();
@@ -123,7 +139,7 @@ public Response findPetsByStatus(
123139
})
124140
@Deprecated
125141
public Response findPetsByTags(
126-
@Parameter(description = "Tags to filter by", required = true/*, allowMultiple = true*/) @QueryParam("tags") String tags) {
142+
@Parameter(description = "Tags to filter by", required = true) @QueryParam("tags") String tags) {
127143
return Response.ok(petData.findPetByTags(tags)).build();
128144
}
129145
}

java/java-jersey2/src/main/java/io/swagger/sample/resource/PetStoreResource.java_ java/java-jersey2/src/main/java/io/swagger/sample/resource/PetStoreResource.java

+31-16
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616

1717
package io.swagger.sample.resource;
1818

19-
import io.swagger.annotations.*;
19+
import io.swagger.oas.annotations.Operation;
20+
import io.swagger.oas.annotations.Parameter;
21+
import io.swagger.oas.annotations.media.Content;
22+
import io.swagger.oas.annotations.media.Schema;
23+
import io.swagger.oas.annotations.responses.ApiResponse;
2024
import io.swagger.sample.data.StoreData;
2125
import io.swagger.sample.model.AuthenticationInfo;
2226
import io.swagger.sample.model.Order;
@@ -25,21 +29,24 @@
2529
import javax.ws.rs.*;
2630

2731
@Path("/store")
28-
@Api(value="/store" , description = "Operations about store")
2932
@Produces({"application/json", "application/xml"})
3033
public class PetStoreResource {
3134
static StoreData storeData = new StoreData();
3235

3336
@GET
3437
@Path("/order/{orderId}")
35-
@ApiOperation(value = "Find purchase order by ID",
36-
notes = "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions",
37-
response = Order.class)
38-
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
39-
@ApiResponse(code = 404, message = "Order not found") })
38+
@Operation(
39+
summary = "Find purchase order by ID",
40+
description = "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions",
41+
responses = {
42+
@ApiResponse(content = @Content(schema = @Schema(implementation = Order.class))),
43+
@ApiResponse(responseCode = "400", description = "Invalid ID supplied"),
44+
@ApiResponse(responseCode = "404", description = "Order not found")
45+
}
46+
)
4047
public Response getOrderById(
4148
@BeanParam AuthenticationInfo info,
42-
@ApiParam(value = "ID of order to fetch") @PathParam("orderId") Long orderId)
49+
@Parameter(description = "ID of order to fetch") @PathParam("orderId") Long orderId)
4350
throws io.swagger.sample.exception.NotFoundException {
4451
Order order = storeData.findOrderById(orderId);
4552
if (null != order) {
@@ -51,24 +58,32 @@ public Response getOrderById(
5158

5259
@POST
5360
@Path("/order")
54-
@ApiOperation(value = "Place an order for a pet",
55-
response = Order.class)
56-
@ApiResponses({ @ApiResponse(code = 400, message = "Invalid Order") })
61+
@Operation(
62+
summary = "Place an order for a pet",
63+
responses = {
64+
@ApiResponse(content = @Content(schema = @Schema(implementation = Order.class))),
65+
@ApiResponse(responseCode = "400", description = "Invalid Order")
66+
}
67+
)
5768
public Response placeOrder(
5869
@BeanParam AuthenticationInfo info,
59-
@ApiParam(value = "order placed for purchasing the pet", required = true) Order order) {
70+
@Parameter(description = "order placed for purchasing the pet", required = true) Order order) {
6071
storeData.placeOrder(order);
6172
return Response.ok().entity("").build();
6273
}
6374

6475
@DELETE
6576
@Path("/order/{orderId}")
66-
@ApiOperation(value = "Delete purchase order by ID")
67-
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
68-
@ApiResponse(code = 404, message = "Order not found") })
77+
@Operation(
78+
summary = "Delete purchase order by ID",
79+
responses = {
80+
@ApiResponse(responseCode = "400", description = "Invalid ID supplied"),
81+
@ApiResponse(responseCode = "404", description = "Order not found")
82+
}
83+
)
6984
public Response deleteOrder(
7085
@BeanParam AuthenticationInfo info,
71-
@ApiParam(value = "ID of order to delete") @PathParam("orderId") Long orderId) {
86+
@Parameter(description = "ID of order to delete") @PathParam("orderId") Long orderId) {
7287
if (storeData.deleteOrder(orderId)) {
7388
return Response.ok().entity("").build();
7489
} else {

java/java-jersey2/src/main/java/io/swagger/sample/resource/SwaggerListingResource.java

-37
This file was deleted.

java/java-jersey2/src/main/java/io/swagger/sample/util/ApiAuthorizationFilterImpl.java_ java/java-jersey2/src/main/java/io/swagger/sample/util/ApiAuthorizationFilterImpl.java

+9-35
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818

1919
import io.swagger.core.filter.AbstractSpecFilter;
2020
import io.swagger.model.ApiDescription;
21-
import io.swagger.models.Model;
22-
import io.swagger.models.Operation;
23-
import io.swagger.models.parameters.Parameter;
24-
import io.swagger.models.properties.Property;
21+
import io.swagger.oas.models.Operation;
2522
import org.slf4j.Logger;
2623
import org.slf4j.LoggerFactory;
2724

2825
import java.util.List;
2926
import java.util.Map;
27+
import java.util.Optional;
3028

3129
/**
3230
*
@@ -46,37 +44,6 @@
4644
public class ApiAuthorizationFilterImpl extends AbstractSpecFilter {
4745
static Logger logger = LoggerFactory.getLogger(ApiAuthorizationFilterImpl.class);
4846

49-
public boolean isOperationAllowed(
50-
Operation operation,
51-
ApiDescription api,
52-
Map<String, List<String>> params,
53-
Map<String, String> cookies,
54-
Map<String, List<String>> headers) {
55-
if(!api.getMethod().equals("get") || api.getPath().startsWith("/store"))
56-
return checkKey(params, headers);
57-
return true;
58-
}
59-
60-
public boolean isParamAllowed(
61-
Parameter parameter,
62-
Operation operation,
63-
ApiDescription api,
64-
Map<String, List<String>> params,
65-
Map<String, String> cookies,
66-
Map<String, List<String>> headers) {
67-
return true;
68-
}
69-
70-
public boolean isPropertyAllowed(
71-
Model model,
72-
Property property,
73-
String propertyName,
74-
Map<String, List<String>> params,
75-
Map<String, String> cookies,
76-
Map<String, List<String>> headers) {
77-
return true;
78-
}
79-
8047
public boolean checkKey(Map<String, List<String>> params, Map<String, List<String>> headers) {
8148
String keyValue = null;
8249
if(params.containsKey("api_key"))
@@ -91,6 +58,13 @@ public boolean checkKey(Map<String, List<String>> params, Map<String, List<Strin
9158
return false;
9259
}
9360

61+
@Override
62+
public Optional<Operation> filterOperation(Operation operation, ApiDescription api, Map<String, List<String>> params, Map<String, String> cookies, Map<String, List<String>> headers) {
63+
if(!api.getMethod().equals("get") || api.getPath().startsWith("/store"))
64+
return checkKey(params, headers) ? Optional.of(operation) : Optional.empty();
65+
return Optional.empty();
66+
}
67+
9468
public boolean isRemovingUnreferencedDefinitions() {
9569
return true;
9670
}

pom.xml

+9-18
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,6 @@
240240
<groupId>org.mortbay.jetty</groupId>
241241
<artifactId>jetty-maven-plugin</artifactId>
242242
<version>${jetty-version}</version>
243-
<dependencies>
244-
<dependency>
245-
<groupId>com.sun.jersey</groupId>
246-
<artifactId>jersey-servlet</artifactId>
247-
<version>${jersey-version}</version>
248-
</dependency>
249-
</dependencies>
250243
</plugin>
251244
<plugin>
252245
<artifactId>maven-enforcer-plugin</artifactId>
@@ -398,9 +391,8 @@
398391
</dependency>
399392
<dependency>
400393
<groupId>javax.servlet</groupId>
401-
<artifactId>servlet-api</artifactId>
394+
<artifactId>javax.servlet-api</artifactId>
402395
<version>${servlet-api-version}</version>
403-
<scope>provided</scope>
404396
</dependency>
405397
<dependency>
406398
<groupId>org.slf4j</groupId>
@@ -411,22 +403,22 @@
411403
<dependency>
412404
<groupId>com.sun.jersey</groupId>
413405
<artifactId>jersey-client</artifactId>
414-
<version>${jersey-version}</version>
406+
<version>${jersey2-version}</version>
415407
</dependency>
416408
<dependency>
417409
<groupId>com.sun.jersey</groupId>
418410
<artifactId>jersey-core</artifactId>
419-
<version>${jersey-version}</version>
411+
<version>${jersey2-version}</version>
420412
</dependency>
421413
<dependency>
422414
<groupId>com.sun.jersey</groupId>
423415
<artifactId>jersey-json</artifactId>
424-
<version>${jersey-version}</version>
416+
<version>${jersey2-version}</version>
425417
</dependency>
426418
<dependency>
427419
<groupId>com.sun.jersey</groupId>
428420
<artifactId>jersey-servlet</artifactId>
429-
<version>${jersey-version}</version>
421+
<version>${jersey2-version}</version>
430422
</dependency>
431423
</dependencies>
432424
</dependencyManagement>
@@ -437,11 +429,10 @@
437429
<swagger-ui-version>2.1.4</swagger-ui-version>
438430
<scala-version>2.10.4</scala-version>
439431
<felix-version>2.3.4</felix-version>
440-
<servlet-api-version>2.5</servlet-api-version>
441-
<jetty-version>9.2.14.v20151106</jetty-version>
442-
<jersey2-version>2.24</jersey2-version>
443-
<jackson-version>2.4.2</jackson-version>
444-
<jackson-guava-version>2.4.2</jackson-guava-version>
432+
<servlet-api-version>3.1.0</servlet-api-version>
433+
<jersey2-version>2.26</jersey2-version>
434+
<jetty-version>9.4.6.v20170531</jetty-version>
435+
<jackson-version>2.9.1</jackson-version>
445436
<logback-version>1.0.1</logback-version>
446437

447438
<junit-version>4.8.1</junit-version>

0 commit comments

Comments
 (0)