Skip to content

Commit 7bbb883

Browse files
committed
Generate JAXRS and SpringMVC samples to demo Authorization annotations
1 parent 6477a27 commit 7bbb883

32 files changed

+196
-106
lines changed
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# Swagger generated server
22

33
## Overview
4-
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
4+
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
55
[swagger-spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
6-
is an example of building a swagger-enabled scalatra server.
6+
is an example of building a swagger-enabled JAX-RS server.
77

8-
This example uses the [scalatra](http://scalatra.org/) framework. To see how to make this your own, look here:
9-
10-
[README](https://github.com/swagger-api/swagger-codegen/tree/master/samples/server-generator/scalatra)
8+
This example uses the [JAX-RS](https://jax-rs-spec.java.net/) framework.

samples/server/petstore/jaxrs/src/gen/java/io/swagger/api/ApiException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.swagger.api;
22

3-
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-08-23T23:29:16.812-07:00")
3+
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-10-16T21:16:23.957-04:00")
44
public class ApiException extends Exception{
55
private int code;
66
public ApiException (int code, String msg) {

samples/server/petstore/jaxrs/src/gen/java/io/swagger/api/ApiOriginFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import javax.servlet.*;
66
import javax.servlet.http.HttpServletResponse;
77

8-
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-08-23T23:29:16.812-07:00")
8+
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-10-16T21:16:23.957-04:00")
99
public class ApiOriginFilter implements javax.servlet.Filter {
1010
public void doFilter(ServletRequest request, ServletResponse response,
1111
FilterChain chain) throws IOException, ServletException {

samples/server/petstore/jaxrs/src/gen/java/io/swagger/api/ApiResponseMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import javax.xml.bind.annotation.XmlTransient;
44

55
@javax.xml.bind.annotation.XmlRootElement
6-
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-08-23T23:29:16.812-07:00")
6+
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-10-16T21:16:23.957-04:00")
77
public class ApiResponseMessage {
88
public static final int ERROR = 1;
99
public static final int WARNING = 2;

samples/server/petstore/jaxrs/src/gen/java/io/swagger/api/NotFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.swagger.api;
22

3-
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-08-23T23:29:16.812-07:00")
3+
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-10-16T21:16:23.957-04:00")
44
public class NotFoundException extends ApiException {
55
private int code;
66
public NotFoundException (int code, String msg) {

samples/server/petstore/jaxrs/src/gen/java/io/swagger/api/PetApi.java

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
@io.swagger.annotations.Api(value = "/pet", description = "the pet API")
29-
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-08-23T23:29:16.812-07:00")
29+
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-10-16T21:16:23.957-04:00")
3030
public class PetApi {
3131

3232
private final PetApiService delegate = PetApiServiceFactory.getPetApi();
@@ -35,106 +35,147 @@ public class PetApi {
3535

3636
@Consumes({ "application/json", "application/xml" })
3737
@Produces({ "application/json", "application/xml" })
38-
@io.swagger.annotations.ApiOperation(value = "Update an existing pet", notes = "", response = Void.class)
38+
@io.swagger.annotations.ApiOperation(value = "Update an existing pet", notes = "", response = Void.class, authorizations = {
39+
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
40+
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
41+
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
42+
})
43+
})
3944
@io.swagger.annotations.ApiResponses(value = {
40-
@io.swagger.annotations.ApiResponse(code = 405, message = "Validation exception", response = Void.class),
45+
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class),
4146

4247
@io.swagger.annotations.ApiResponse(code = 404, message = "Pet not found", response = Void.class),
4348

44-
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class) })
49+
@io.swagger.annotations.ApiResponse(code = 405, message = "Validation exception", response = Void.class) })
4550

4651
public Response updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ) Pet body)
4752
throws NotFoundException {
48-
return delegate.updatePet(body);
53+
return delegate.updatePet(body);
4954
}
5055
@POST
5156

5257
@Consumes({ "application/json", "application/xml" })
5358
@Produces({ "application/json", "application/xml" })
54-
@io.swagger.annotations.ApiOperation(value = "Add a new pet to the store", notes = "", response = Void.class)
59+
@io.swagger.annotations.ApiOperation(value = "Add a new pet to the store", notes = "", response = Void.class, authorizations = {
60+
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
61+
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
62+
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
63+
})
64+
})
5565
@io.swagger.annotations.ApiResponses(value = {
5666
@io.swagger.annotations.ApiResponse(code = 405, message = "Invalid input", response = Void.class) })
5767

5868
public Response addPet(@ApiParam(value = "Pet object that needs to be added to the store" ) Pet body)
5969
throws NotFoundException {
60-
return delegate.addPet(body);
70+
return delegate.addPet(body);
6171
}
6272
@GET
6373
@Path("/findByStatus")
6474

6575
@Produces({ "application/json", "application/xml" })
66-
@io.swagger.annotations.ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma seperated strings", response = Pet.class, responseContainer = "List")
76+
@io.swagger.annotations.ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma seperated strings", response = Pet.class, responseContainer = "List", authorizations = {
77+
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
78+
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
79+
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
80+
})
81+
})
6782
@io.swagger.annotations.ApiResponses(value = {
6883
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"),
6984

7085
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid status value", response = Pet.class, responseContainer = "List") })
7186

7287
public Response findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter", defaultValue="available") @QueryParam("status") List<String> status)
7388
throws NotFoundException {
74-
return delegate.findPetsByStatus(status);
89+
return delegate.findPetsByStatus(status);
7590
}
7691
@GET
7792
@Path("/findByTags")
7893

7994
@Produces({ "application/json", "application/xml" })
80-
@io.swagger.annotations.ApiOperation(value = "Finds Pets by tags", notes = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List")
95+
@io.swagger.annotations.ApiOperation(value = "Finds Pets by tags", notes = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List", authorizations = {
96+
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
97+
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
98+
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
99+
})
100+
})
81101
@io.swagger.annotations.ApiResponses(value = {
82102
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"),
83103

84104
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid tag value", response = Pet.class, responseContainer = "List") })
85105

86106
public Response findPetsByTags(@ApiParam(value = "Tags to filter by") @QueryParam("tags") List<String> tags)
87107
throws NotFoundException {
88-
return delegate.findPetsByTags(tags);
108+
return delegate.findPetsByTags(tags);
89109
}
90110
@GET
91111
@Path("/{petId}")
92112

93113
@Produces({ "application/json", "application/xml" })
94-
@io.swagger.annotations.ApiOperation(value = "Find pet by ID", notes = "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", response = Pet.class)
114+
@io.swagger.annotations.ApiOperation(value = "Find pet by ID", notes = "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", response = Pet.class, authorizations = {
115+
@io.swagger.annotations.Authorization(value = "api_key"),
116+
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
117+
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
118+
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
119+
})
120+
})
95121
@io.swagger.annotations.ApiResponses(value = {
96-
@io.swagger.annotations.ApiResponse(code = 404, message = "Pet not found", response = Pet.class),
97-
98122
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Pet.class),
99123

100-
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid ID supplied", response = Pet.class) })
124+
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid ID supplied", response = Pet.class),
125+
126+
@io.swagger.annotations.ApiResponse(code = 404, message = "Pet not found", response = Pet.class) })
101127

102128
public Response getPetById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathParam("petId") Long petId)
103129
throws NotFoundException {
104-
return delegate.getPetById(petId);
130+
return delegate.getPetById(petId);
105131
}
106132
@POST
107133
@Path("/{petId}")
108134
@Consumes({ "application/x-www-form-urlencoded" })
109135
@Produces({ "application/json", "application/xml" })
110-
@io.swagger.annotations.ApiOperation(value = "Updates a pet in the store with form data", notes = "", response = Void.class)
136+
@io.swagger.annotations.ApiOperation(value = "Updates a pet in the store with form data", notes = "", response = Void.class, authorizations = {
137+
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
138+
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
139+
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
140+
})
141+
})
111142
@io.swagger.annotations.ApiResponses(value = {
112143
@io.swagger.annotations.ApiResponse(code = 405, message = "Invalid input", response = Void.class) })
113144

114145
public Response updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true ) @PathParam("petId") String petId,
115146
@ApiParam(value = "Updated name of the pet" )@FormParam("name") String name,
116147
@ApiParam(value = "Updated status of the pet" )@FormParam("status") String status)
117148
throws NotFoundException {
118-
return delegate.updatePetWithForm(petId,name,status);
149+
return delegate.updatePetWithForm(petId,name,status);
119150
}
120151
@DELETE
121152
@Path("/{petId}")
122153

123154
@Produces({ "application/json", "application/xml" })
124-
@io.swagger.annotations.ApiOperation(value = "Deletes a pet", notes = "", response = Void.class)
155+
@io.swagger.annotations.ApiOperation(value = "Deletes a pet", notes = "", response = Void.class, authorizations = {
156+
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
157+
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
158+
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
159+
})
160+
})
125161
@io.swagger.annotations.ApiResponses(value = {
126162
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid pet value", response = Void.class) })
127163

128164
public Response deletePet(@ApiParam(value = "Pet id to delete",required=true ) @PathParam("petId") Long petId,
129165
@ApiParam(value = "" )@HeaderParam("api_key") String apiKey)
130166
throws NotFoundException {
131-
return delegate.deletePet(petId,apiKey);
167+
return delegate.deletePet(petId,apiKey);
132168
}
133169
@POST
134170
@Path("/{petId}/uploadImage")
135171
@Consumes({ "multipart/form-data" })
136172
@Produces({ "application/json", "application/xml" })
137-
@io.swagger.annotations.ApiOperation(value = "uploads an image", notes = "", response = Void.class)
173+
@io.swagger.annotations.ApiOperation(value = "uploads an image", notes = "", response = Void.class, authorizations = {
174+
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
175+
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
176+
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
177+
})
178+
})
138179
@io.swagger.annotations.ApiResponses(value = {
139180
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Void.class) })
140181

@@ -143,7 +184,7 @@ public Response uploadFile(@ApiParam(value = "ID of pet to update",required=true
143184
@FormDataParam("file") InputStream inputStream,
144185
@FormDataParam("file") FormDataContentDisposition fileDetail)
145186
throws NotFoundException {
146-
return delegate.uploadFile(petId,additionalMetadata,fileDetail);
187+
return delegate.uploadFile(petId,additionalMetadata,fileDetail);
147188
}
148189
}
149190

samples/server/petstore/jaxrs/src/gen/java/io/swagger/api/PetApiService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import javax.ws.rs.core.Response;
2020

21-
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-08-23T23:29:16.812-07:00")
21+
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-10-16T21:16:23.957-04:00")
2222
public abstract class PetApiService {
2323

2424
public abstract Response updatePet(Pet body)

samples/server/petstore/jaxrs/src/gen/java/io/swagger/api/StoreApi.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
@io.swagger.annotations.Api(value = "/store", description = "the store API")
29-
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-08-23T23:29:16.812-07:00")
29+
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-10-16T21:16:23.957-04:00")
3030
public class StoreApi {
3131

3232
private final StoreApiService delegate = StoreApiServiceFactory.getStoreApi();
@@ -35,13 +35,15 @@ public class StoreApi {
3535
@Path("/inventory")
3636

3737
@Produces({ "application/json", "application/xml" })
38-
@io.swagger.annotations.ApiOperation(value = "Returns pet inventories by status", notes = "Returns a map of status codes to quantities", response = Integer.class, responseContainer = "Map")
38+
@io.swagger.annotations.ApiOperation(value = "Returns pet inventories by status", notes = "Returns a map of status codes to quantities", response = Integer.class, responseContainer = "Map", authorizations = {
39+
@io.swagger.annotations.Authorization(value = "api_key")
40+
})
3941
@io.swagger.annotations.ApiResponses(value = {
4042
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Integer.class, responseContainer = "Map") })
4143

4244
public Response getInventory()
4345
throws NotFoundException {
44-
return delegate.getInventory();
46+
return delegate.getInventory();
4547
}
4648
@POST
4749
@Path("/order")
@@ -55,37 +57,37 @@ public Response getInventory()
5557

5658
public Response placeOrder(@ApiParam(value = "order placed for purchasing the pet" ) Order body)
5759
throws NotFoundException {
58-
return delegate.placeOrder(body);
60+
return delegate.placeOrder(body);
5961
}
6062
@GET
6163
@Path("/order/{orderId}")
6264

6365
@Produces({ "application/json", "application/xml" })
6466
@io.swagger.annotations.ApiOperation(value = "Find purchase order by ID", notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", response = Order.class)
6567
@io.swagger.annotations.ApiResponses(value = {
66-
@io.swagger.annotations.ApiResponse(code = 404, message = "Order not found", response = Order.class),
67-
6868
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Order.class),
6969

70-
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid ID supplied", response = Order.class) })
70+
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid ID supplied", response = Order.class),
71+
72+
@io.swagger.annotations.ApiResponse(code = 404, message = "Order not found", response = Order.class) })
7173

7274
public Response getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathParam("orderId") String orderId)
7375
throws NotFoundException {
74-
return delegate.getOrderById(orderId);
76+
return delegate.getOrderById(orderId);
7577
}
7678
@DELETE
7779
@Path("/order/{orderId}")
7880

7981
@Produces({ "application/json", "application/xml" })
8082
@io.swagger.annotations.ApiOperation(value = "Delete purchase order by ID", notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", response = Void.class)
8183
@io.swagger.annotations.ApiResponses(value = {
82-
@io.swagger.annotations.ApiResponse(code = 404, message = "Order not found", response = Void.class),
84+
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class),
8385

84-
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class) })
86+
@io.swagger.annotations.ApiResponse(code = 404, message = "Order not found", response = Void.class) })
8587

8688
public Response deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathParam("orderId") String orderId)
8789
throws NotFoundException {
88-
return delegate.deleteOrder(orderId);
90+
return delegate.deleteOrder(orderId);
8991
}
9092
}
9193

samples/server/petstore/jaxrs/src/gen/java/io/swagger/api/StoreApiService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import javax.ws.rs.core.Response;
2020

21-
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-08-23T23:29:16.812-07:00")
21+
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JaxRSServerCodegen", date = "2015-10-16T21:16:23.957-04:00")
2222
public abstract class StoreApiService {
2323

2424
public abstract Response getInventory()

0 commit comments

Comments
 (0)