From 7179d83aa05b9125ed5708477681c3004fc0821b Mon Sep 17 00:00:00 2001 From: Helen Kosova Date: Fri, 28 Apr 2017 00:54:41 +0300 Subject: [PATCH 1/8] Fixed typos in operation descriptions: muliple -> multiple seperated -> separated --- java/inflector-dropwizard-guice/src/main/swagger/swagger.yaml | 4 ++-- java/inflector-dropwizard/src/main/swagger/swagger.yaml | 4 ++-- java/inflector-jetty-webxml/src/main/swagger/swagger.yaml | 4 ++-- .../inflector-springboot-jersey/src/main/swagger/swagger.yaml | 4 ++-- .../src/main/java/io/swagger/sample/resource/PetResource.java | 2 +- .../src/java/io/swagger/sample/resource/PetResource.java | 4 ++-- .../src/main/java/io/swagger/sample/resource/PetResource.java | 4 ++-- .../main/java/io/swagger/sample/resources/PetResource.java | 2 +- .../src/main/java/io/swagger/sample/resource/PetResource.java | 4 ++-- .../src/main/java/io/swagger/sample/resource/PetResource.java | 2 +- .../src/main/java/io/swagger/sample/resource/PetResource.java | 2 +- .../src/main/java/io/swagger/sample/resource/PetResource.java | 2 +- .../src/main/java/io/swagger/sample/resource/PetResource.java | 4 ++-- .../src/main/java/io/swagger/sample/resource/PetResource.java | 2 +- .../src/main/java/io/swagger/sample/resource/PetResource.java | 4 ++-- .../src/main/java/io/swagger/sample/resource/PetResource.java | 4 ++-- scala/scala-play2.4/app/controllers/PetApiController.scala | 4 ++-- 17 files changed, 28 insertions(+), 28 deletions(-) diff --git a/java/inflector-dropwizard-guice/src/main/swagger/swagger.yaml b/java/inflector-dropwizard-guice/src/main/swagger/swagger.yaml index 008ad436..a7f83630 100644 --- a/java/inflector-dropwizard-guice/src/main/swagger/swagger.yaml +++ b/java/inflector-dropwizard-guice/src/main/swagger/swagger.yaml @@ -89,7 +89,7 @@ paths: tags: - pet summary: Finds Pets by status - description: Multiple status values can be provided with comma seperated strings + description: Multiple status values can be provided with comma separated strings operationId: findPetsByStatus consumes: - application/xml @@ -131,7 +131,7 @@ paths: tags: - pet summary: Finds Pets by tags - description: "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing." + description: "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing." operationId: findPetsByTags produces: - application/xml diff --git a/java/inflector-dropwizard/src/main/swagger/swagger.yaml b/java/inflector-dropwizard/src/main/swagger/swagger.yaml index 008ad436..a7f83630 100644 --- a/java/inflector-dropwizard/src/main/swagger/swagger.yaml +++ b/java/inflector-dropwizard/src/main/swagger/swagger.yaml @@ -89,7 +89,7 @@ paths: tags: - pet summary: Finds Pets by status - description: Multiple status values can be provided with comma seperated strings + description: Multiple status values can be provided with comma separated strings operationId: findPetsByStatus consumes: - application/xml @@ -131,7 +131,7 @@ paths: tags: - pet summary: Finds Pets by tags - description: "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing." + description: "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing." operationId: findPetsByTags produces: - application/xml diff --git a/java/inflector-jetty-webxml/src/main/swagger/swagger.yaml b/java/inflector-jetty-webxml/src/main/swagger/swagger.yaml index d8238e18..5245f741 100644 --- a/java/inflector-jetty-webxml/src/main/swagger/swagger.yaml +++ b/java/inflector-jetty-webxml/src/main/swagger/swagger.yaml @@ -92,7 +92,7 @@ paths: tags: - pet summary: Finds Pets by status - description: Multiple status values can be provided with comma seperated strings + description: Multiple status values can be provided with comma separated strings operationId: findPetsByStatus consumes: - application/xml @@ -134,7 +134,7 @@ paths: tags: - pet summary: Finds Pets by tags - description: "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing." + description: "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing." operationId: findPetsByTags produces: - application/xml diff --git a/java/inflector-springboot-jersey/src/main/swagger/swagger.yaml b/java/inflector-springboot-jersey/src/main/swagger/swagger.yaml index 93e3e8db..ae5d85c9 100644 --- a/java/inflector-springboot-jersey/src/main/swagger/swagger.yaml +++ b/java/inflector-springboot-jersey/src/main/swagger/swagger.yaml @@ -89,7 +89,7 @@ paths: tags: - pet summary: Finds Pets by status - description: Multiple status values can be provided with comma seperated strings + description: Multiple status values can be provided with comma separated strings operationId: findPetsByStatus consumes: - application/xml @@ -131,7 +131,7 @@ paths: tags: - pet summary: Finds Pets by tags - description: "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing." + description: "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing." operationId: findPetsByTags produces: - application/xml diff --git a/java/java-dropwizard/src/main/java/io/swagger/sample/resource/PetResource.java b/java/java-dropwizard/src/main/java/io/swagger/sample/resource/PetResource.java index 60ae5073..2077baa2 100644 --- a/java/java-dropwizard/src/main/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-dropwizard/src/main/java/io/swagger/sample/resource/PetResource.java @@ -73,7 +73,7 @@ public Response updatePet( @Path("/findByStatus") @ApiOperation( value = "Finds Pets by status", - notes = "Multiple status values can be provided with comma seperated strings", + notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid status value") }) diff --git a/java/java-grails2/src/java/io/swagger/sample/resource/PetResource.java b/java/java-grails2/src/java/io/swagger/sample/resource/PetResource.java index 24069013..1e67985c 100644 --- a/java/java-grails2/src/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-grails2/src/java/io/swagger/sample/resource/PetResource.java @@ -69,7 +69,7 @@ public Response updatePet( @GET @Path("/findByStatus") - @ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma seperated strings", response = Pet.class, responseContainer = "List") + @ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid status value") }) public Response findPetsByStatus( @ApiParam(value = "Status values that need to be considered for filter", required = true, defaultValue = "available", allowableValues = "available,pending,sold", allowMultiple = true) @QueryParam("status") String status) { @@ -78,7 +78,7 @@ public Response findPetsByStatus( @GET @Path("/findByTags") - @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") + @ApiOperation(value = "Finds Pets by tags", notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tag value") }) @Deprecated public Response findPetsByTags( diff --git a/java/java-jaxrs-cxf/src/main/java/io/swagger/sample/resource/PetResource.java b/java/java-jaxrs-cxf/src/main/java/io/swagger/sample/resource/PetResource.java index 4c5adeb5..75ceeb63 100644 --- a/java/java-jaxrs-cxf/src/main/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-jaxrs-cxf/src/main/java/io/swagger/sample/resource/PetResource.java @@ -71,7 +71,7 @@ public Response updatePet( @GET @Path("/findByStatus") @ApiOperation(value = "Finds Pets by status", - notes = "Multiple status values can be provided with comma seperated strings", + notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid status value") }) @@ -83,7 +83,7 @@ public Response findPetsByStatus( @GET @Path("/findByTags") @ApiOperation(value = "Finds Pets by tags", - notes = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", + notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tag value") }) diff --git a/java/java-jaxrs-wink/src/main/java/io/swagger/sample/resources/PetResource.java b/java/java-jaxrs-wink/src/main/java/io/swagger/sample/resources/PetResource.java index ff88031f..726917f0 100644 --- a/java/java-jaxrs-wink/src/main/java/io/swagger/sample/resources/PetResource.java +++ b/java/java-jaxrs-wink/src/main/java/io/swagger/sample/resources/PetResource.java @@ -82,7 +82,7 @@ public Response updatePet( @GET @Path("/findByStatus") @ApiOperation(value = "Finds Pets by status", - notes = "Multiple status values can be provided with comma seperated strings", + notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid status value") }) diff --git a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java index 11f84090..dce5ef62 100644 --- a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java @@ -130,7 +130,7 @@ public Response updatePet( @GET @Path("/findByStatus") @ApiOperation(value = "Finds Pets by status", - notes = "Multiple status values can be provided with comma seperated strings", + notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid status value") }) @@ -142,7 +142,7 @@ public Response findPetsByStatus( @GET @Path("/findByTags") @ApiOperation(value = "Finds Pets by tags", - notes = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", + notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tag value") }) diff --git a/java/java-jersey-jaxrs-multi-use-basepath/src/main/java/io/swagger/sample/resource/PetResource.java b/java/java-jersey-jaxrs-multi-use-basepath/src/main/java/io/swagger/sample/resource/PetResource.java index 47b1fef4..af2827f2 100644 --- a/java/java-jersey-jaxrs-multi-use-basepath/src/main/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-jersey-jaxrs-multi-use-basepath/src/main/java/io/swagger/sample/resource/PetResource.java @@ -149,7 +149,7 @@ public Response findPetsByStatus( @GET @Path("/findByTags") @ApiOperation(value = "Finds Pets by tags", - notes = "Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tag value") }) diff --git a/java/java-jersey-jaxrs-multi/src/main/java/io/swagger/sample/resource/PetResource.java b/java/java-jersey-jaxrs-multi/src/main/java/io/swagger/sample/resource/PetResource.java index 47b1fef4..af2827f2 100644 --- a/java/java-jersey-jaxrs-multi/src/main/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-jersey-jaxrs-multi/src/main/java/io/swagger/sample/resource/PetResource.java @@ -149,7 +149,7 @@ public Response findPetsByStatus( @GET @Path("/findByTags") @ApiOperation(value = "Finds Pets by tags", - notes = "Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tag value") }) diff --git a/java/java-jersey-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java b/java/java-jersey-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java index 47b1fef4..af2827f2 100644 --- a/java/java-jersey-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-jersey-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java @@ -149,7 +149,7 @@ public Response findPetsByStatus( @GET @Path("/findByTags") @ApiOperation(value = "Finds Pets by tags", - notes = "Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tag value") }) diff --git a/java/java-jersey-spring/src/main/java/io/swagger/sample/resource/PetResource.java b/java/java-jersey-spring/src/main/java/io/swagger/sample/resource/PetResource.java index 2a0b4faa..4997506f 100644 --- a/java/java-jersey-spring/src/main/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-jersey-spring/src/main/java/io/swagger/sample/resource/PetResource.java @@ -49,7 +49,7 @@ Response updatePet( @GET @Path("/findByStatus") @ApiOperation(value = "Finds Pets by status", - notes = "Multiple status values can be provided with comma seperated strings", + notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid status value")}) @@ -59,7 +59,7 @@ Response findPetsByStatus( @GET @Path("/findByTags") @ApiOperation(value = "Finds Pets by tags", - notes = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", + notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tag value")}) diff --git a/java/java-jersey2-guice/src/main/java/io/swagger/sample/resource/PetResource.java b/java/java-jersey2-guice/src/main/java/io/swagger/sample/resource/PetResource.java index 10a97048..a90e7a65 100644 --- a/java/java-jersey2-guice/src/main/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-jersey2-guice/src/main/java/io/swagger/sample/resource/PetResource.java @@ -84,7 +84,7 @@ public Response findPetsByStatus( @GET @Path("/findByTags") @ApiOperation(value = "Finds Pets by tags", - notes = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", + notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tag value") }) diff --git a/java/java-jersey2/src/main/java/io/swagger/sample/resource/PetResource.java b/java/java-jersey2/src/main/java/io/swagger/sample/resource/PetResource.java index a83e7a8d..0117fcad 100644 --- a/java/java-jersey2/src/main/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-jersey2/src/main/java/io/swagger/sample/resource/PetResource.java @@ -70,7 +70,7 @@ public Response updatePet( @GET @Path("/findByStatus") @ApiOperation(value = "Finds Pets by status", - notes = "Multiple status values can be provided with comma seperated strings", + notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid status value") }) @@ -84,7 +84,7 @@ public Response findPetsByStatus( @GET @Path("/findByTags") @ApiOperation(value = "Finds Pets by tags", - notes = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", + notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tag value") }) diff --git a/java/java-mule/src/main/java/io/swagger/sample/resource/PetResource.java b/java/java-mule/src/main/java/io/swagger/sample/resource/PetResource.java index 82936a03..346cfa75 100644 --- a/java/java-mule/src/main/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-mule/src/main/java/io/swagger/sample/resource/PetResource.java @@ -99,7 +99,7 @@ public Response updatePet( @GET @Path("/findByStatus") @ApiOperation(value = "Finds Pets by status", - notes = "Multiple status values can be provided with comma seperated strings", + notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid status value") }) @@ -111,7 +111,7 @@ public Response findPetsByStatus( @GET @Path("/findByTags") @ApiOperation(value = "Finds Pets by tags", - notes = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", + notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tag value") }) diff --git a/scala/scala-play2.4/app/controllers/PetApiController.scala b/scala/scala-play2.4/app/controllers/PetApiController.scala index b45d5c9d..4e653e15 100644 --- a/scala/scala-play2.4/app/controllers/PetApiController.scala +++ b/scala/scala-play2.4/app/controllers/PetApiController.scala @@ -89,7 +89,7 @@ class PetApiController extends BaseApiController { @ApiOperation(nickname = "findPetByStatus", value = "Finds Pets by status", - notes = "Multiple status values can be provided with comma seperated strings", + notes = "Multiple status values can be provided with comma separated strings", response = classOf[models.Pet], responseContainer = "List", httpMethod = "GET") @ApiResponses(Array( new ApiResponse(code = 400, message = "Invalid status value"))) @@ -103,7 +103,7 @@ class PetApiController extends BaseApiController { @ApiOperation(nickname = "findPetsByTags", value = "Finds Pets by tags", - notes = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", + notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = classOf[models.Pet], responseContainer = "List", httpMethod = "GET") @ApiResponses(Array( new ApiResponse(code = 400, message = "Invalid tag value"))) From 9a5d14f86e7a2e2369643ffff738101bb52c1a35 Mon Sep 17 00:00:00 2001 From: Dennis Kieselhorst Date: Sun, 25 Jun 2017 16:49:43 +0200 Subject: [PATCH 2/8] fixed duplicate artifactId --- java/java-jersey-jaxrs-multi-use-basepath/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/java-jersey-jaxrs-multi-use-basepath/pom.xml b/java/java-jersey-jaxrs-multi-use-basepath/pom.xml index 334291a4..137de674 100644 --- a/java/java-jersey-jaxrs-multi-use-basepath/pom.xml +++ b/java/java-jersey-jaxrs-multi-use-basepath/pom.xml @@ -7,9 +7,9 @@ 4.0.0 io.swagger - swagger-java-jersey-multi-sample-app + swagger-java-jersey-multi-use-basepath-sample-app war - swagger-java-jersey-jaxrs-multi-app + swagger-java-jersey-jaxrs-multi-use-basepath-app 1.0.0 src/main/java From a561ae213e78094f067b5d4418ba3a948b9e2576 Mon Sep 17 00:00:00 2001 From: Janarthanan Date: Wed, 12 Jul 2017 15:51:22 -0400 Subject: [PATCH 3/8] added new annotations with Anna --- java/java-jaxrs/pom.xml | 18 +- .../java/io/swagger/sample/model/Pet.java | 24 +- .../java/io/swagger/sample/model/User.java | 12 +- .../swagger/sample/resource/PetResource.java | 269 ++++++++++++++---- .../sample/resource/PetStoreResource.java | 112 ++++++-- .../swagger/sample/resource/UserResource.java | 206 +++++++++++--- .../sample/resource/VehicleResource.java | 189 ++++++++---- 7 files changed, 629 insertions(+), 201 deletions(-) diff --git a/java/java-jaxrs/pom.xml b/java/java-jaxrs/pom.xml index a32dfda7..4dc795be 100644 --- a/java/java-jaxrs/pom.xml +++ b/java/java-jaxrs/pom.xml @@ -119,12 +119,7 @@ - - io.swagger - swagger-jaxrs - ${swagger-version} - compile - + ch.qos.logback logback-classic @@ -163,6 +158,17 @@ com.sun.jersey jersey-servlet + + vuk + vuk + 2 + + 0 diff --git a/java/java-jaxrs/src/main/java/io/swagger/sample/model/Pet.java b/java/java-jaxrs/src/main/java/io/swagger/sample/model/Pet.java index 57bda02d..871952c1 100644 --- a/java/java-jaxrs/src/main/java/io/swagger/sample/model/Pet.java +++ b/java/java-jaxrs/src/main/java/io/swagger/sample/model/Pet.java @@ -1,5 +1,5 @@ /** - * Copyright 2016 SmartBear Software + * Copyright 2015 SmartBear Software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package io.swagger.sample.model; import io.swagger.annotations.*; +import io.swagger.oas.annotations.media.Schema; import java.util.List; import java.util.ArrayList; @@ -24,7 +25,6 @@ import javax.xml.bind.annotation.*; @XmlRootElement(name = "Pet") -@ApiModel(value = "Pet", subTypes = {Cat.class}, discriminator = "type") public class Pet { private long id; private Category category; @@ -82,7 +82,11 @@ public void setTags(List tags) { } @XmlElement(name = "status") - @ApiModelProperty(value = "pet status in the store", allowableValues = "available,pending,sold") + @Schema( + name = "status", + title = "pet status in the store", + _enum = {"available", "pending", "sold"} + ) public String getStatus() { return status; } @@ -90,16 +94,4 @@ public String getStatus() { public void setStatus(String status) { this.status = status; } - - private String type; - - @ApiModelProperty(required = true) - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - -} +} \ No newline at end of file diff --git a/java/java-jaxrs/src/main/java/io/swagger/sample/model/User.java b/java/java-jaxrs/src/main/java/io/swagger/sample/model/User.java index 35f8a5ba..2e35a8c6 100644 --- a/java/java-jaxrs/src/main/java/io/swagger/sample/model/User.java +++ b/java/java-jaxrs/src/main/java/io/swagger/sample/model/User.java @@ -1,5 +1,5 @@ /** - * Copyright 2016 SmartBear Software + * Copyright 2015 SmartBear Software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package io.swagger.sample.model; import io.swagger.annotations.*; +import io.swagger.oas.annotations.media.Schema; import javax.xml.bind.annotation.*; @@ -95,7 +96,14 @@ public void setPhone(String phone) { } @XmlElement(name = "userStatus") - @ApiModelProperty(value = "User Status", allowableValues = "1-registered,2-active,3-closed") + @Schema( + name = "userStatus", + title = "User Status", + _enum = {"1-registered", "2-active", "3-closed"} + ) + + + public int getUserStatus() { return userStatus; } diff --git a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java index 11f84090..10408ce5 100644 --- a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java @@ -1,5 +1,5 @@ /** - * Copyright 2016 SmartBear Software + * Copyright 2015 SmartBear Software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,19 @@ */ package io.swagger.sample.resource; +//import io.swagger.annotations.Api; +import io.swagger.oas.annotations.Operation; +import io.swagger.oas.annotations.Parameter; +import io.swagger.oas.annotations.callbacks.Callback; +import io.swagger.oas.annotations.info.Info; +import io.swagger.oas.annotations.info.License; +import io.swagger.oas.annotations.info.Contact; +import io.swagger.oas.annotations.media.Content; +import io.swagger.oas.annotations.media.Schema; +import io.swagger.oas.annotations.media.ExampleObject; +//import io.swagger.oas.annotations.parameters.Parameters; +import io.swagger.oas.annotations.responses.ApiResponse; -import io.swagger.annotations.*; -import io.swagger.annotations.ApiResponse; import io.swagger.sample.data.PetData; import io.swagger.sample.model.Pet; import io.swagger.sample.exception.NotFoundException; @@ -30,28 +40,49 @@ import javax.ws.rs.*; @Path("/pet") -@Api(value = "/pet", description = "Operations about pets", authorizations = { - @Authorization(value = "petstore_auth", - scopes = { - @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), - @AuthorizationScope(scope = "read:pets", description = "read your pets") - }) -}, tags = "pet") + +@Api(value = "/pet", description = "Operations about pets", tags = "pet") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) +@Info( + title = "Pets Operations", + version = "1.0", + description = "Operations about pets", + license = @License(name = "Apache 2.0", url = "http://www.apache.org/licenses/LICENSE-2.0.html"), + contact = @Contact(name = "", url = "", email = "") +) public class PetResource { + static PetData petData = new PetData(); @GET @Path("/{petId}") - @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 = @Authorization(value = "api_key") + @Operation( + method = "GET", + summary = "Find pet by ID", + description = "Returns a pet when ID <= 10. ID > 10 or nonintegers will simulate API error conditions", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid ID supplied" + ), + @ApiResponse( + responseCode = "404", + description = "Pet not found" + ), + @ApiResponse( + responseCode = "200", + content = @Content( + mediaType = "application/json", + schema = @Schema(type = "array", implementation = Pet.class)) + ) + } ) - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"), - @ApiResponse(code = 404, message = "Pet not found") }) - public Response getPetById( - @ApiParam(value = "ID of pet that needs to be fetched", allowableValues = "range[1,10]", required = true) @PathParam("petId") Long petId) + public Response getPetById( + @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) throws NotFoundException { Pet pet = petData.getPetById(petId); if (pet != null) { @@ -63,15 +94,28 @@ public Response getPetById( @GET @Path("/{petId}/download") - @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 = @Authorization(value = "api_key") + @Operation( + method = "GET", + summary = "Find pet by ID and download it", + description = "Downloads a pet when ID <= 10. ID > 10 or nonintegers will simulate API error conditions", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid ID supplied" + ), + @ApiResponse( + responseCode = "404", + description = "Pet not found" + ) + } ) - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"), - @ApiResponse(code = 404, message = "Pet not found") }) public Response downloadFile( - @ApiParam(value = "ID of pet that needs to be fetched", allowableValues = "range[1,10]", required = true) @PathParam("petId") Long petId) + @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) throws NotFoundException { StreamingOutput stream = new StreamingOutput() { @Override @@ -92,12 +136,33 @@ public void write(OutputStream output) throws IOException { @DELETE @Path("/{petId}") - @ApiOperation(value = "Deletes a pet") - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"), - @ApiResponse(code = 404, message = "Pet not found")}) + @Operation( + method = "DELETE", + summary = "Deletes a pet by ID", + description = "Deletes a pet when ID <= 10. ID > 10 or nonintegers will simulate API error conditions", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid ID supplied" + ), + @ApiResponse( + responseCode = "404", + description = "Pet not found" + ) + } + ) public Response deletePet( - @ApiParam() @HeaderParam("api_key") String apiKey, - @ApiParam(value = "Pet id to delete", required = true)@PathParam("petId") Long petId) { + @Parameter( + name = "apiKey", + description = "authentication key to access this method", + schema = @Schema(type = "String", implementation = String.class) + ) @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 { @@ -107,63 +172,149 @@ public Response deletePet( @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - @ApiOperation(value = "Add a new pet to the store") - @ApiResponses(value = { @ApiResponse(code = 405, message = "Invalid input", response = io.swagger.sample.model.ApiResponse.class) }) + @Operation( + method = "POST", + summary = "Add pet to store", + description = "Add a new pet to the store", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid input", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiResponse.class)) + ) + } + ) public Response addPet( - @ApiParam(value = "Pet object that needs to be added to the store", required = true) Pet pet) { + @Parameter( + name ="pet", + description = "Pet to add", + required = true, + schema = @Schema(implementation = Pet.class)) Pet pet) { Pet updatedPet = petData.addPet(pet); return Response.ok().entity(updatedPet).build(); } @PUT @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - @ApiOperation(value = "Update an existing pet") - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"), - @ApiResponse(code = 404, message = "Pet not found"), - @ApiResponse(code = 405, message = "Validation exception") }) - public Response updatePet( - @ApiParam(value = "Pet object that needs to be added to the store", required = true) Pet pet) { + @Operation( + method = "PUT", + summary = "Update an existing pet", + description = "Update an existing pet with the given new attributes", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid ID supplied" + ), + @ApiResponse( + responseCode = "404", + description = "Pet not found" + ), + @ApiResponse( + responseCode = "405", + description = "Validation exception" + ) + }) + public Response updatePet( + @Parameter( + name ="pet", + description = "Pet to update with", + required = true, + schema = @Schema(implementation = Pet.class)) Pet pet) { Pet updatedPet = petData.addPet(pet); return Response.ok().entity(updatedPet).build(); } @GET @Path("/findByStatus") - @ApiOperation(value = "Finds Pets by status", - notes = "Multiple status values can be provided with comma seperated strings", - response = Pet.class, - responseContainer = "List") - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid status value") }) + @Operation( + + method = "GET", + summary = "Finds Pets by status", + description = "Find all the Pets with the given status; Multiple status values can be provided with comma seperated strings", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid status value" + ), + @ApiResponse( + responseCode = "200", + content = @Content( + mediaType = "application/json", + schema = @Schema(type = "list", implementation = Pet.class)) + ) + }) public Response findPetsByStatus( - @ApiParam(value = "Status values that need to be considered for filter", required = true, defaultValue = "available", allowableValues = "available,pending,sold", allowMultiple = true) @QueryParam("status") String status) { - return Response.ok(petData.findPetByStatus(status)).build(); + @Parameter( + name = "status", + description = "Status values that need to be considered for filter", + required = true, + schema = @Schema(implementation = String.class), + content = { + @Content( + examples = { + @ExampleObject( + name = "Available", + value = "available", + summary = "Retrieves all the pets that are available"), + @ExampleObject( + name = "Pending", + value = "pending", + summary = "Retrieves all the pets that are pending to be sold"), + @ExampleObject( + name = "Sold", + value = "sold", + summary = "Retrieves all the pets that are sold"), + } + ) + }, + allowEmptyValue = true) String statttus) { + return Response.ok(petData.findPetByStatus(statttus)).build(); } @GET @Path("/findByTags") - @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") - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tag value") }) + @Callback(operation = + @Operation( + method = "GET", + summary = "Finds Pets by tags", + description = "Find Pets by tags; Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid tag value" + ), + @ApiResponse( + responseCode = "200", + content = @Content( + mediaType = "application/json", + schema = @Schema(type = "list", implementation = Pet.class)) + ) + })) @Deprecated public Response findPetsByTags( @HeaderParam("api_key") String api_key, - @ApiParam(value = "Tags to filter by", required = true, allowMultiple = true) @QueryParam("tags") String tags) { + @Parameter(name = "tags", description = "Tags to filter by", required = true) @QueryParam("tags") String tags) { return Response.ok(petData.findPetByTags(tags)).build(); } @POST @Path("/{petId}") @Consumes({MediaType.APPLICATION_FORM_URLENCODED}) - @ApiOperation(value = "Updates a pet in the store with form data", - consumes = MediaType.APPLICATION_FORM_URLENCODED) - @ApiResponses(value = { - @ApiResponse(code = 405, message = "Invalid input")}) + @Operation( + method = "POST", + summary = "Updates a pet in the store with form data", + responses = { + @ApiResponse( + responseCode = "405", + description = "Validation exception" + ) + }) public Response updatePetWithForm ( - @ApiParam(value = "ID of pet that needs to be updated", required = true)@PathParam("petId") Long petId, - @ApiParam(value = "Updated name of the pet", required = false)@FormParam("name") String name, - @ApiParam(value = "Updated status of the pet", required = false)@FormParam("status") String status) { + @Parameter(name = "petId", description = "ID of pet that needs to be updated", required = true) @PathParam("petId") Long petId, + @Parameter(name = "name", description = "Updated name of the pet") @FormParam("name") String name, + @Parameter(name = "status", description = "Updated status of the pet") @FormParam("status") String status) { Pet pet = petData.getPetById(petId); if(pet != null) { if(name != null && !"".equals(name)) diff --git a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetStoreResource.java b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetStoreResource.java index 7f9c1022..011b08ea 100644 --- a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetStoreResource.java +++ b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetStoreResource.java @@ -1,5 +1,5 @@ /** - * Copyright 2016 SmartBear Software + * Copyright 2015 SmartBear Software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,10 @@ package io.swagger.sample.resource; -import io.swagger.annotations.*; +import io.swagger.oas.annotations.*; +import io.swagger.oas.annotations.media.Content; +import io.swagger.oas.annotations.media.Schema; +import io.swagger.oas.annotations.responses.ApiResponse; import io.swagger.sample.data.StoreData; import io.swagger.sample.model.Order; import io.swagger.sample.exception.NotFoundException; @@ -27,7 +30,7 @@ import javax.ws.rs.*; @Path("/store") -@Api(value="/store" , description = "Operations about store") +@Schema(name="/store") @Produces({"application/json", "application/xml"}) public class PetStoreResource { static StoreData storeData = new StoreData(); @@ -36,25 +39,57 @@ public class PetStoreResource { @GET @Path("/inventory") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - @ApiOperation(value = "Returns pet inventories by status", - notes = "Returns a map of status codes to quantities", - response = Integer.class, - responseContainer = "map", - authorizations = @Authorization(value = "api_key") - ) + @Operation( + method = "get", + summary = "Returns pet inventories by status", + description = "Returns a map of status codes to quantities", + responses = { + @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + schema = @Schema(type = "map", implementation = Integer.class) + ) + ) + } + ) public java.util.Map getInventory() { return petData.getInventoryByStatus(); } @GET @Path("/order/{orderId}") - @ApiOperation(value = "Find purchase order by ID", - notes = "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions", - response = Order.class) - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"), - @ApiResponse(code = 404, message = "Order not found") }) + @Operation( + method = "get", + summary = "Find purchase order by ID", + description = "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions", + responses = { + @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + schema = @Schema(implementation = Order.class) + )), + @ApiResponse( + responseCode = "400", + description = "Invalid ID supplied", + content = @Content( + schema = @Schema(implementation = Order.class) + )), + @ApiResponse( + responseCode = "404", + description = "Order not found", + content = @Content( + schema = @Schema(implementation = Order.class) + )) + }) public Response getOrderById( - @ApiParam(value = "ID of pet that needs to be fetched", allowableValues = "range[1,10]", required = true) + @Parameter( + name = "orderId", + description = "ID of pet that needs to be fetched", + schema = @Schema(type = "integer", minimum = "1", maximum = "10"), + required = true + ) @PathParam("orderId") Long orderId) throws NotFoundException { Order order = storeData.findOrderById(orderId); @@ -67,23 +102,52 @@ public Response getOrderById( @POST @Path("/order") - @ApiOperation(value = "Place an order for a pet") - @ApiResponses({ @ApiResponse(code = 400, message = "Invalid Order") }) + @Operation( + method = "post", + summary = "Place an order for a pet", + responses = { + @ApiResponse( + responseCode = "200", + description = "successful operation" + ), + @ApiResponse( + responseCode = "400", + description = "Invalid Order" + ) + }) public Order placeOrder( - @ApiParam(value = "order placed for purchasing the pet", - required = true) Order order) { + @Parameter( + description = "order placed for purchasing the pet", + required = true + ) + Order order) { storeData.placeOrder(order); return storeData.placeOrder(order); } @DELETE @Path("/order/{orderId}") - @ApiOperation(value = "Delete purchase order by ID", - notes = "For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors") - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"), - @ApiResponse(code = 404, message = "Order not found") }) + @Operation( + method = "delete", + summary = "Delete purchase order by ID", + description = "For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid ID supplied" + ), + @ApiResponse( + responseCode = "404", + description = "Order not found" + ) + }) public Response deleteOrder( - @ApiParam(value = "ID of the order that needs to be deleted", allowableValues = "range[1,infinity]", required = true) + @Parameter( + name = "orderId", + description = "ID of the order that needs to be deleted", + schema = @Schema(type = "integer", minimum = "1", maximum = "inifinity"), + required = true + ) @PathParam("orderId") Long orderId) { if (storeData.deleteOrder(orderId)) { return Response.ok().entity("").build(); diff --git a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/UserResource.java b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/UserResource.java index 84e7e894..aec37e0d 100644 --- a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/UserResource.java +++ b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/UserResource.java @@ -1,5 +1,5 @@ /** - * Copyright 2016 SmartBear Software + * Copyright 2015 SmartBear Software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,10 @@ package io.swagger.sample.resource; -import io.swagger.annotations.*; +import io.swagger.oas.annotations.*; +import io.swagger.oas.annotations.media.Schema; +import io.swagger.oas.annotations.responses.ApiResponse; +import io.swagger.oas.annotations.media.Content; import io.swagger.sample.data.UserData; import io.swagger.sample.model.User; import io.swagger.sample.exception.ApiException; @@ -26,26 +29,46 @@ import javax.ws.rs.*; @Path("/user") -@Api(value="/user", description = "Operations about user") +@Schema(name = "/user") @Produces({"application/json", "application/xml"}) public class UserResource { static UserData userData = new UserData(); @POST - @ApiOperation(value = "Create user", - notes = "This can only be done by the logged in user.", - position = 1) + @Operation( + method = "post", + summary = "Create user", + description = "This can only be done by the logged in user.", + responses = { + @ApiResponse( + description = "successful operation" + ) + }) public Response createUser( - @ApiParam(value = "Created user object", required = true) User user) { + @Parameter( + description = "Created user object", + schema = @Schema(implementation = User.class), + required = true + ) User user) { userData.addUser(user); return Response.ok().entity("").build(); } @POST @Path("/createWithArray") - @ApiOperation(value = "Creates list of users with given input array", - position = 2) - public Response createUsersWithArrayInput(@ApiParam(value = "List of user object", required = true) User[] users) { + @Operation( + method = "post", + summary = "Creates list of users with given input array", + responses = { + @ApiResponse( + description = "successful operation" + ) + }) + public Response createUsersWithArrayInput( + @Parameter( + description = "List of user object", + required = true + ) User[] users) { for (User user : users) { userData.addUser(user); } @@ -54,9 +77,18 @@ public Response createUsersWithArrayInput(@ApiParam(value = "List of user object @POST @Path("/createWithList") - @ApiOperation(value = "Creates list of users with given input array", - position = 3) - public Response createUsersWithListInput(@ApiParam(value = "List of user object", required = true) java.util.List users) { + @Operation( + method = "post", + summary = "Creates list of users with given input array", + responses = { + @ApiResponse( + description = "successful operation" + ) + }) + public Response createUsersWithListInput( + @Parameter( + description = "List of user object", + required = true) java.util.List users) { for (User user : users) { userData.addUser(user); } @@ -65,29 +97,59 @@ public Response createUsersWithListInput(@ApiParam(value = "List of user object" @PUT @Path("/{username}") - @ApiOperation(value = "Updated user", - notes = "This can only be done by the logged in user.", - position = 4) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid user supplied"), - @ApiResponse(code = 404, message = "User not found") }) + @Operation( + method = "put", + summary = "Updated user", + description = "This can only be done by the logged in user.", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid user supplied" + ), + @ApiResponse( + responseCode = "404", + description = "User not found" + ) + }) public Response updateUser( - @ApiParam(value = "name that need to be deleted", required = true) @PathParam("username") String username, - @ApiParam(value = "Updated user object", required = true) User user) { + @Parameter( + name = "username", + description = "name that need to be deleted", + schema = @Schema(type = "string"), + required = true + ) + @PathParam("username") String username, + @Parameter( + description = "Updated user object", + required = true) User user) { userData.addUser(user); return Response.ok().entity("").build(); } @DELETE @Path("/{username}") - @ApiOperation(value = "Delete user", - notes = "This can only be done by the logged in user.", - position = 5) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid username supplied"), - @ApiResponse(code = 404, message = "User not found") }) + @Operation( + method = "delete", + summary = "Delete user", + description = "This can only be done by the logged in user.", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid username supplied" + ), + @ApiResponse( + responseCode = "404", + description = "User not found" + ) + }) public Response deleteUser( - @ApiParam(value = "The name that needs to be deleted", required = true) @PathParam("username") String username) { + @Parameter( + name = "username", + description = "The name that needs to be deleted", + schema = @Schema(type = "string"), + required = true + ) + @PathParam("username") String username) { if (userData.removeUser(username)) { return Response.ok().entity("").build(); } else { @@ -97,15 +159,38 @@ public Response deleteUser( @GET @Path("/{username}") - @ApiOperation(value = "Get user by user name", - response = User.class, - position = 0) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid username supplied"), - @ApiResponse(code = 404, message = "User not found") }) + @Operation( + method = "get", + summary = "Get user by user name", + responses = { + @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) + ) + ) + }) public Response getUserByName( - @ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ", required = true) @PathParam("username") String username) - throws ApiException { + @Parameter( + name = "username", + description = "The name that needs to be fetched. Use user1 for testing.", + schema = @Schema(type = "string"), + required = true + ) + @PathParam("username") String username) throws ApiException { User user = userData.findUserByName(username); if (null != user) { return Response.ok().entity(user).build(); @@ -116,13 +201,40 @@ public Response getUserByName( @GET @Path("/login") - @ApiOperation(value = "Logs user into the system", - response = String.class, - position = 6) - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid username/password supplied") }) + @Operation( + method = "get", + summary = "Logs user into the system", + responses = { + + @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) + )) + }) + public Response loginUser( - @ApiParam(value = "The user name for login", required = true) @QueryParam("username") String username, - @ApiParam(value = "The password for login in clear text", required = true) @QueryParam("password") String password) { + @Parameter( + name = "username", + description = "The user name for login", + schema = @Schema(type = "string"), + required = true + ) + @QueryParam("username") String username, + @Parameter( + name = "password", + description = "The password for login in clear text", + schema = @Schema(type = "string"), + required = true) + @QueryParam("password") String password) { return Response.ok() .entity("logged in user session:" + System.currentTimeMillis()) .build(); @@ -130,8 +242,14 @@ public Response loginUser( @GET @Path("/logout") - @ApiOperation(value = "Logs out current logged in user session", - position = 7) + @Operation( + method = "get", + summary = "Logs out current logged in user session", + responses = { + @ApiResponse( + description = "successful operation" + ) + }) public Response logoutUser() { return Response.ok().entity("").build(); } diff --git a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/VehicleResource.java b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/VehicleResource.java index 6898d7a2..6964fb2d 100644 --- a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/VehicleResource.java +++ b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/VehicleResource.java @@ -16,14 +16,14 @@ package io.swagger.sample.resource; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.sample.data.VehicleData; +// import io.swagger.annotations.Api; +import io.swagger.oas.annotations.Operation; +import io.swagger.oas.annotations.Parameter; +import io.swagger.oas.annotations.media.Content; +import io.swagger.oas.annotations.media.Schema; +import io.swagger.oas.annotations.responses.ApiResponse; +//import io.swagger.annotations.Authorization; +//import io.swagger.annotations.AuthorizationScope; import io.swagger.sample.data.VehicleData; import io.swagger.sample.exception.NotFoundException; import io.swagger.sample.model.Vehicle; @@ -38,7 +38,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.StreamingOutput; @@ -46,28 +45,52 @@ import java.io.OutputStream; @Path("/vehicle") -@Api(value = "/vehicle", description = "Operations about vehicles", authorizations = { - @Authorization(value = "vehiclestore_auth", - scopes = { - @AuthorizationScope(scope = "write:vehicle", description = "modify vehicles in your account"), - @AuthorizationScope(scope = "read:vehicle", description = "read your vehicles") - }) -}, tags = "vehicle") +// @Api(value = "/vehicle", description = "Operations about vehicles", authorizations = { +// @Authorization(value = "vehiclestore_auth", +// scopes = { +// @AuthorizationScope(scope = "write:vehicle", description = "modify vehicles in your account"), +// @AuthorizationScope(scope = "read:vehicle", description = "read your vehicles") +// }) +// }, tags = "vehicle") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public class VehicleResource { static VehicleData vehicleData = new VehicleData(); @GET @Path("/{vehicleId}") - @ApiOperation(value = "Find vehicle by ID", - notes = "Returns a vehicle when ID <= 10. ID > 10 or nonintegers will simulate API error conditions", - response = Vehicle.class, - authorizations = @Authorization(value = "api_key") + @Operation( + method = "GET", + summary = "Find vehicle by ID", + description = "Returns a vehicle when ID <= 10. ID > 10 or nonintegers will simulate API error conditions", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid ID supplied" + ), + @ApiResponse( + responseCode = "404", + description = "Vehicle not found" + ), + @ApiResponse( + responseCode = "200", + description = "Vehicle found", + content = @Content( + mediaType = "application/json", + schema = @Schema(type = "array", implementation = Vehicle.class)) + ) + + } + +//authorizations = @Authorization(value = "api_key") ) - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"), - @ApiResponse(code = 404, message = "Vehicle not found") }) + public Response getVehicleById( - @ApiParam(value = "ID of vehicle that needs to be fetched", allowableValues = "range[1,10]", required = true) @PathParam("vehicleId") Long vehicleId) + @Parameter( + name = "vehicleId", + description = "ID of vehicle that needs to be fetched", + required = true, + schema = @Schema(implementation = Long.class, type = "integer", minimum = "1", maximum = "10") + ) @PathParam("vehicleId") Long vehicleId ) throws NotFoundException { Vehicle vehicle = vehicleData.getVehicleById(vehicleId); if (vehicle != null) { @@ -79,15 +102,29 @@ public Response getVehicleById( @GET @Path("/{vehicleId}/download") - @ApiOperation(value = "Find vehicle by ID", - notes = "Returns a vehicle when ID <= 10. ID > 10 or nonintegers will simulate API error conditions", - response = Vehicle.class, - authorizations = @Authorization(value = "api_key") + @Operation( + method = "GET", + summary = "Find vehicle by ID", + description = "Returns a vehicle when ID <= 10. ID > 10 or nonintegers will simulate API error conditions", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid ID supplied" + ), + @ApiResponse( + responseCode = "404", + description = "Vehicle not found" + ) + } +// authorizations = @Authorization(value = "api_key") ) - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"), - @ApiResponse(code = 404, message = "Vehicle not found") }) public Response downloadFile( - @ApiParam(value = "ID of vehicle that needs to be fetched", allowableValues = "range[1,10]", required = true) @PathParam("vehicleId") Long vehicleId) + @Parameter( + name = "vehicleId", + description = "ID of vehicle that needs to be fetched", + required = true, + schema = @Schema(implementation = Long.class, type = "integer", minimum = "1", maximum = "10") + ) @PathParam("vehicleId") Long vehicleId) throws NotFoundException { StreamingOutput stream = new StreamingOutput() { @Override @@ -108,12 +145,24 @@ public void write(OutputStream output) throws IOException { @DELETE @Path("/{vehicleId}") - @ApiOperation(value = "Deletes a vehicle") - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"), - @ApiResponse(code = 404, message = "Vehicle not found")}) + @Operation( + method = "DELETE", + summary = "Deletes a vehicle", + description = "Deletes a vehicle when ID <= 10. ID > 10 or nonintegers will simulate API error conditions", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid ID supplied" + ), + @ApiResponse( + responseCode = "404", + description = "Vehicle not found" + ) + } + ) public Response deleteVehicle( - @ApiParam() @HeaderParam("api_key") String apiKey, - @ApiParam(value = "Vehicle id to delete", required = true)@PathParam("vehicleId") Long vehicleId) { + @Parameter(name ="apiKey", schema = @Schema(implementation = String.class, type = "string")) @HeaderParam("api_key") String apiKey, + @Parameter(name = "vehicleId", description = "Vehicle id to delete", required = true) @PathParam("vehicleId") Long vehicleId) { if (vehicleData.deleteVehicle(vehicleId)) { return Response.ok().build(); } else { @@ -123,22 +172,47 @@ public Response deleteVehicle( @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - @ApiOperation(value = "Add a new vehicle to the store") - @ApiResponses(value = { @ApiResponse(code = 405, message = "Invalid input", response = io.swagger.sample.model.ApiResponse.class) }) + @Operation( + method= "POST", + summary = "Add a new vehicle to the store", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid input", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiResponse.class)) + ) + }) public Response addVehicle( - @ApiParam(value = "Vehicle object that needs to be added to the store", required = true) Vehicle vehicle) { + @Parameter(name = "vehicle", + description = "Vehicle object that needs to be added to the store", + required = true) Vehicle vehicle) { Vehicle updatedVehicle = vehicleData.addVehicle(vehicle); return Response.ok().entity(updatedVehicle).build(); } @PUT @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - @ApiOperation(value = "Update an existing vehicle") - @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"), - @ApiResponse(code = 404, message = "Vehicle not found"), - @ApiResponse(code = 405, message = "Validation exception") }) + @Operation( + method = "PUT", + summary = "Update an existing vehicle", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid ID supplied" + ), + @ApiResponse( + responseCode = "404", + description = "Vehicle not found" + ), + @ApiResponse( + responseCode = "405", + description = "Validation exception" + ) + }) public Response updateVehicle( - @ApiParam(value = "Vehicle object that needs to be added to the store", required = true) Vehicle vehicle) { + @Parameter(name = "vehicle", description = "Vehicle object that needs to be added to the store", required = true) Vehicle vehicle) { Vehicle updatedVehicle = vehicleData.addVehicle(vehicle); return Response.ok().entity(updatedVehicle).build(); } @@ -146,14 +220,29 @@ public Response updateVehicle( @POST @Path("/{vehicleId}") @Consumes({MediaType.APPLICATION_FORM_URLENCODED}) - @ApiOperation(value = "Updates a vehicle in the store with form data", - consumes = MediaType.APPLICATION_FORM_URLENCODED) - @ApiResponses(value = { - @ApiResponse(code = 405, message = "Invalid input")}) + @Operation( + method = "POST", + summary = "Updates a vehicle in the store with form data", + responses = { + @ApiResponse( + responseCode = "400", + description = "Invalid input" + ) + }) public Response updateVehicleWithForm ( - @ApiParam(value = "ID of vehicle that needs to be updated", required = true)@PathParam("vehicleId") Long vehicleId, - @ApiParam(value = "Updated name of the vehicle", required = false)@FormParam("name") String name, - @ApiParam(value = "Updated status of the vehicle", required = false)@FormParam("status") String status) { + @Parameter( + name = "vehicleId", + description = "ID of vehicle that needs to be updated", + required = true, + schema = @Schema(implementation = Long.class)) @PathParam("vehicleId") Long vehicleId, + @Parameter( + name = "name", + description = "Updates name of the vehicle", + schema = @Schema(implementation = String.class)) @FormParam("name") String name, + @Parameter( + name = "status", + description = "Updates status of the vehicle", + schema = @Schema(implementation = String.class)) @FormParam("status") String status) { Vehicle vehicle = vehicleData.getVehicleById(vehicleId); if(vehicle != null) { if(name != null && !"".equals(name)) From d36f0a2fb33e49a5d614286d61f0649897020837 Mon Sep 17 00:00:00 2001 From: Anna Safonov Date: Wed, 19 Jul 2017 14:53:44 -0400 Subject: [PATCH 4/8] minor updates for pet and store resources --- .../swagger/sample/resource/PetResource.java | 117 ++++++++++++------ .../sample/resource/PetStoreResource.java | 17 +-- 2 files changed, 92 insertions(+), 42 deletions(-) diff --git a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java index 10408ce5..85b00245 100644 --- a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java +++ b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java @@ -15,7 +15,7 @@ */ package io.swagger.sample.resource; -//import io.swagger.annotations.Api; + import io.swagger.oas.annotations.Operation; import io.swagger.oas.annotations.Parameter; import io.swagger.oas.annotations.callbacks.Callback; @@ -24,8 +24,8 @@ import io.swagger.oas.annotations.info.Contact; import io.swagger.oas.annotations.media.Content; import io.swagger.oas.annotations.media.Schema; +import io.swagger.oas.annotations.parameters.RequestBody; import io.swagger.oas.annotations.media.ExampleObject; -//import io.swagger.oas.annotations.parameters.Parameters; import io.swagger.oas.annotations.responses.ApiResponse; import io.swagger.sample.data.PetData; @@ -40,8 +40,9 @@ import javax.ws.rs.*; @Path("/pet") - -@Api(value = "/pet", description = "Operations about pets", tags = "pet") +@Schema( + name = "/pet", + description = "Operations about pets") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Info( title = "Pets Operations", @@ -59,21 +60,25 @@ public class PetResource { @Operation( method = "GET", summary = "Find pet by ID", - description = "Returns a pet when ID <= 10. ID > 10 or nonintegers will simulate API error conditions", + description = "Returns a pet when ID is less than or equal to 10. If ID is greater than 10 or nonintegers, will simulate API error conditions", responses = { @ApiResponse( responseCode = "400", - description = "Invalid ID supplied" + description = "Invalid ID supplied", + content = @Content( + mediaType = "none") ), @ApiResponse( responseCode = "404", - description = "Pet not found" + description = "Pet not found", + content = @Content( + mediaType = "none") ), @ApiResponse( responseCode = "200", content = @Content( - mediaType = "application/json", - schema = @Schema(type = "array", implementation = Pet.class)) + mediaType = "application/json", + schema = @Schema(type = "array", implementation = Pet.class)) ) } ) @@ -82,7 +87,11 @@ public Response getPetById( 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) + schema = @Schema( + implementation = Long.class, + maximum = "10", + minimum = "1")) + @PathParam("petId") Long petId) throws NotFoundException { Pet pet = petData.getPetById(petId); if (pet != null) { @@ -97,15 +106,17 @@ public Response getPetById( @Operation( method = "GET", summary = "Find pet by ID and download it", - description = "Downloads a pet when ID <= 10. ID > 10 or nonintegers will simulate API error conditions", + description = "Returns a pet when ID is less than or equal to 10. If ID is greater than 10 or nonintegers, will simulate API error conditions", responses = { @ApiResponse( responseCode = "400", - description = "Invalid ID supplied" + description = "Invalid ID supplied", + content = @Content(mediaType = "none") ), @ApiResponse( responseCode = "404", - description = "Pet not found" + description = "Pet not found", + content = @Content(mediaType = "none") ) } ) @@ -114,7 +125,10 @@ public Response downloadFile( name = "petId", description = "ID of pet that needs to be fetched", required = true, - schema = @Schema(implementation = Long.class, maximum = "10", minimum = "1") + schema = @Schema( + implementation = Long.class, + maximum = "10", + minimum = "1") ) @PathParam("petId") Long petId) throws NotFoundException { StreamingOutput stream = new StreamingOutput() { @@ -139,7 +153,7 @@ public void write(OutputStream output) throws IOException { @Operation( method = "DELETE", summary = "Deletes a pet by ID", - description = "Deletes a pet when ID <= 10. ID > 10 or nonintegers will simulate API error conditions", + description = "Returns a pet when ID is less than or equal to 10. If ID is greater than 10 or nonintegers, will simulate API error conditions", responses = { @ApiResponse( responseCode = "400", @@ -155,14 +169,17 @@ public Response deletePet( @Parameter( name = "apiKey", description = "authentication key to access this method", - schema = @Schema(type = "String", implementation = String.class) - ) @HeaderParam("api_key") String apiKey, + schema = @Schema(type = "String", implementation = String.class)) + @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) { + schema = @Schema( + implementation = Long.class, + maximum = "10", + minimum = "1")) + @PathParam("petId") Long petId) { if (petData.deletePet(petId)) { return Response.ok().build(); } else { @@ -172,6 +189,7 @@ public Response deletePet( @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Operation( method = "POST", summary = "Add pet to store", @@ -184,11 +202,18 @@ public Response deletePet( mediaType = "application/json", schema = @Schema(implementation = ApiResponse.class)) ) - } + }, + requestBody = @RequestBody( + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Pet.class)), + required = true, + description = "example of a new pet to add" + ) ) public Response addPet( @Parameter( - name ="pet", + name ="addPet", description = "Pet to add", required = true, schema = @Schema(implementation = Pet.class)) Pet pet) { @@ -205,21 +230,24 @@ public Response addPet( responses = { @ApiResponse( responseCode = "400", - description = "Invalid ID supplied" + description = "Invalid ID supplied", + content = @Content(mediaType = "application/json") ), @ApiResponse( responseCode = "404", - description = "Pet not found" + description = "Pet not found", + content = @Content(mediaType = "application/json") ), @ApiResponse( responseCode = "405", - description = "Validation exception" + description = "Validation exception", + content = @Content(mediaType = "application/json") ) }) public Response updatePet( @Parameter( - name ="pet", - description = "Pet to update with", + name ="petAttribute", + description = "Attribute to update existing pet record", required = true, schema = @Schema(implementation = Pet.class)) Pet pet) { Pet updatedPet = petData.addPet(pet); @@ -236,7 +264,8 @@ public Response updatePet( responses = { @ApiResponse( responseCode = "400", - description = "Invalid status value" + description = "Invalid status value", + content = @Content(mediaType = "none") ), @ApiResponse( responseCode = "200", @@ -269,8 +298,8 @@ public Response findPetsByStatus( } ) }, - allowEmptyValue = true) String statttus) { - return Response.ok(petData.findPetByStatus(statttus)).build(); + allowEmptyValue = true) String status) { + return Response.ok(petData.findPetByStatus(status)).build(); } @GET @@ -279,11 +308,13 @@ public Response findPetsByStatus( @Operation( method = "GET", summary = "Finds Pets by tags", + deprecated = true, description = "Find Pets by tags; Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", responses = { @ApiResponse( responseCode = "400", - description = "Invalid tag value" + description = "Invalid tag value", + content = @Content(mediaType = "none") ), @ApiResponse( responseCode = "200", @@ -295,7 +326,12 @@ public Response findPetsByStatus( @Deprecated public Response findPetsByTags( @HeaderParam("api_key") String api_key, - @Parameter(name = "tags", description = "Tags to filter by", required = true) @QueryParam("tags") String tags) { + @Parameter( + name = "tags", + description = "Tags to filter by", + required = true, + deprecated = true) + @QueryParam("tags") String tags) { return Response.ok(petData.findPetByTags(tags)).build(); } @@ -308,13 +344,24 @@ public Response findPetsByTags( responses = { @ApiResponse( responseCode = "405", - description = "Validation exception" + description = "Validation exception", + content = @Content(mediaType = "none") ) }) public Response updatePetWithForm ( - @Parameter(name = "petId", description = "ID of pet that needs to be updated", required = true) @PathParam("petId") Long petId, - @Parameter(name = "name", description = "Updated name of the pet") @FormParam("name") String name, - @Parameter(name = "status", description = "Updated status of the pet") @FormParam("status") String status) { + @Parameter( + name = "petId", + description = "ID of pet that needs to be updated", + required = true) + @PathParam("petId") Long petId, + @Parameter( + name = "name", + description = "Updated name of the pet") + @FormParam("name") String name, + @Parameter( + name = "status", + description = "Updated status of the pet") + @FormParam("status") String status) { Pet pet = petData.getPetById(petId); if(pet != null) { if(name != null && !"".equals(name)) diff --git a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetStoreResource.java b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetStoreResource.java index 011b08ea..ae580ba2 100644 --- a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetStoreResource.java +++ b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/PetStoreResource.java @@ -46,10 +46,7 @@ public class PetStoreResource { responses = { @ApiResponse( responseCode = "200", - description = "successful operation", - content = @Content( - schema = @Schema(type = "map", implementation = Integer.class) - ) + description = "successful operation" ) } ) @@ -62,7 +59,7 @@ public java.util.Map getInventory() { @Operation( method = "get", summary = "Find purchase order by ID", - description = "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions", + description = "For valid response try integer IDs with value between the integers of 1 and 10. Other values will generated exceptions", responses = { @ApiResponse( responseCode = "200", @@ -87,7 +84,10 @@ public Response getOrderById( @Parameter( name = "orderId", description = "ID of pet that needs to be fetched", - schema = @Schema(type = "integer", minimum = "1", maximum = "10"), + schema = @Schema( + type = "long", + minimum = "1", + maximum = "10"), required = true ) @PathParam("orderId") Long orderId) @@ -145,7 +145,10 @@ public Response deleteOrder( @Parameter( name = "orderId", description = "ID of the order that needs to be deleted", - schema = @Schema(type = "integer", minimum = "1", maximum = "inifinity"), + schema = @Schema( + type = "long", + minimum = "1" + ), required = true ) @PathParam("orderId") Long orderId) { From f9eaba60c4785289b9f55cec79c3994e84d7e7af Mon Sep 17 00:00:00 2001 From: Janarthanan Date: Wed, 19 Jul 2017 15:19:50 -0400 Subject: [PATCH 5/8] updated and fixed annotations for UserResources --- .../swagger/sample/resource/UserResource.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/UserResource.java b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/UserResource.java index aec37e0d..84d12e4f 100644 --- a/java/java-jaxrs/src/main/java/io/swagger/sample/resource/UserResource.java +++ b/java/java-jaxrs/src/main/java/io/swagger/sample/resource/UserResource.java @@ -46,10 +46,12 @@ public class UserResource { }) public Response createUser( @Parameter( + name = "user", description = "Created user object", schema = @Schema(implementation = User.class), required = true - ) User user) { + ) + User user) { userData.addUser(user); return Response.ok().entity("").build(); } @@ -61,6 +63,7 @@ public Response createUser( summary = "Creates list of users with given input array", responses = { @ApiResponse( + responseCode = "200", description = "successful operation" ) }) @@ -82,6 +85,7 @@ public Response createUsersWithArrayInput( summary = "Creates list of users with given input array", responses = { @ApiResponse( + responseCode = "200", description = "successful operation" ) }) @@ -208,19 +212,11 @@ public Response getUserByName( @ApiResponse( responseCode = "200", - description = "successful operation", - content = @Content( - schema = @Schema(implementation = String.class) - )), - + description = "successful operation"), @ApiResponse( responseCode = "400", - description = "Invalid username/password supplied", - content = @Content( - schema = @Schema(implementation = String.class) - )) + description = "Invalid username/password supplied") }) - public Response loginUser( @Parameter( name = "username", From 10a85782c2c18066d2ea5c7c286b81cd93571442 Mon Sep 17 00:00:00 2001 From: Janarthanan Date: Thu, 10 Aug 2017 11:14:08 -0400 Subject: [PATCH 6/8] working on config builder --- .../swagger/sample/servlet/SampleServlet.java | 201 ++++++++++++++---- 1 file changed, 158 insertions(+), 43 deletions(-) diff --git a/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java b/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java index 1e3a63a1..736e78df 100644 --- a/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java +++ b/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java @@ -1,67 +1,75 @@ package io.swagger.sample.servlet; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Contact; -import io.swagger.annotations.Info; -import io.swagger.annotations.License; -import io.swagger.annotations.SwaggerDefinition; -import io.swagger.annotations.Tag; import io.swagger.sample.model.SampleData; import io.swagger.util.Json; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -@SwaggerDefinition( - info = @Info( - description = "This is a sample server", - version = "1.0.0", - title = "Swagger Sample Servlet", - termsOfService = "http://swagger.io/terms/", - contact = @Contact(name = "Sponge-Bob", email = "apiteam@swagger.io", url = "http://swagger.io"), - license = @License(name = "Apache 2.0", url = "http://www.apache.org/licenses/LICENSE-2.0.html") - ), - consumes = {"application/json", "application/xml"}, - produces = {"application/json", "application/xml"}, - schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS}, - tags = {@Tag(name = "users", description = "Operations about user")} -) -@Api(value = "/sample/users", description = "gets some data from a servlet") -public class SampleServlet extends HttpServlet { - - @ApiOperation(httpMethod = "GET", value = "Resource to get a user", response = SampleData.class, nickname = "getUser") - @ApiResponses({@ApiResponse(code = 400, message = "Invalid input", response = io.swagger.sample.model.ApiResponse - .class)}) - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "User ID", required = true, dataType = "integer", paramType = - "query"), - @ApiImplicitParam(name = "name", value = "User's name", required = true, dataType = "string", paramType = - "query"), - @ApiImplicitParam(name = "email", value = "User's email", required = true, dataType = "string", paramType - = "query"), - @ApiImplicitParam(name = "age", value = "User's age", required = true, dataType = "integer", paramType = - "query"), - @ApiImplicitParam(name = "dateOfBirth", value = "User's date of birth, in dd-MM-yyyy format", required = - true, dataType = "java.util.Date", paramType = "query")}) +import io.swagger.oas.models.Components; +import io.swagger.oas.models.OpenAPI; +import io.swagger.oas.models.Operation; +import io.swagger.oas.models.PathItem; +import io.swagger.oas.models.Paths; +import io.swagger.oas.models.info.Info; +import io.swagger.oas.models.media.Content; +import io.swagger.oas.models.media.MediaType; +import io.swagger.oas.models.media.Schema; +import io.swagger.oas.models.responses.ApiResponse; +import io.swagger.oas.models.responses.ApiResponses; +import io.swagger.oas.web.OpenAPIConfig; +//import io.swagger.oas.web.OpenAPIConfig; +import io.swagger.oas.web.OpenAPIConfigBuilder; +//@SwaggerDefinition( +// info = @Info( +// description = "This is a sample server", +// version = "1.0.0", +// title = "Swagger Sample Servlet", +// termsOfService = "http://swagger.io/terms/", +// contact = @Contact(name = "Sponge-Bob", email = "apiteam@swagger.io", url = "http://swagger.io"), +// license = @License(name = "Apache 2.0", url = "http://www.apache.org/licenses/LICENSE-2.0.html") +// ), +// consumes = {"application/json", "application/xml"}, +// produces = {"application/json", "application/xml"}, +// schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS}, +// tags = {@Tag(name = "users", description = "Operations about user")} +//) +//@Api(value = "/sample/users", description = "gets some data from a servlet") +public class SampleServlet extends HttpServlet implements OpenAPIConfigBuilder { + +// @ApiOperation(httpMethod = "GET", value = "Resource to get a user", response = SampleData.class, nickname = "getUser") +// @ApiResponses({@ApiResponse(code = 400, message = "Invalid input", response = io.swagger.sample.model.ApiResponse +// .class)}) +// @ApiImplicitParams({ +// @ApiImplicitParam(name = "id", value = "User ID", required = true, dataType = "integer", paramType = +// "query"), +// @ApiImplicitParam(name = "name", value = "User's name", required = true, dataType = "string", paramType = +// "query"), +// @ApiImplicitParam(name = "email", value = "User's email", required = true, dataType = "string", paramType +// = "query"), +// @ApiImplicitParam(name = "age", value = "User's age", required = true, dataType = "integer", paramType = +// "query"), +// @ApiImplicitParam(name = "dateOfBirth", value = "User's date of birth, in dd-MM-yyyy format", required = +// true, dataType = "java.util.Date", paramType = "query")}) public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String result; try { final Integer id = Integer.parseInt(request.getParameter("id")); final String name = request.getParameter("name"); final String email = request.getParameter("email"); - final Integer age = Integer.parseInt(request.getParameter("age")); + final int age = Integer.parseInt(request.getParameter("age")); final Date dateOfBirth = new SimpleDateFormat("dd-MM-yyyy").parse(request.getParameter("dateOfBirth")); result = Json.pretty(new SampleData(id, name, email, age, dateOfBirth)); } catch (Exception ex) { @@ -70,4 +78,111 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro response.getOutputStream().write(result.getBytes(StandardCharsets.UTF_8)); } + + @Override + public OpenAPIConfig build(Map arg0) { + OpenAPI oai = new OpenAPI(); + + Info info = new Info(); + info.setTitle("Swagger Sample Servlet"); + info.setVersion("1.0.0"); + oai.setInfo(info); + + Components components = new Components(); + Map schemas = new HashMap(); + List required = new ArrayList(); + required.add("name"); + required.add("id"); + required.add("email"); + required.add("age"); + + Map properties = new HashMap(); + properties.put("name", new Schema() + .type("string")); + properties.put("id", new Schema() + .type("integer") + .format("int32")); + properties.put("email", new Schema() + .type("string")); + properties.put("age", new Schema() + .type("integer") + .format("int32")); + + schemas.put("User", new Schema() + .type("object") + .required(required) + .properties(properties)); + + components.setSchemas(schemas); + Paths paths = new Paths(); + PathItem pathItem = new PathItem(); + + Operation operation = new Operation(); + operation.setDescription("Resource to get a user"); + ApiResponses responses = new ApiResponses(); + ApiResponse item = new ApiResponse(); + item.setDescription("Successful"); + Content content = new Content(); + MediaType mediaType = new MediaType(); + Schema schema = new Schema(); + schema.set$ref("#/components/schemas/User"); + mediaType.setSchema(schema); + content.addMediaType("application/json", mediaType); + item.setContent(content); + + operation.setDescription("Resource to get a user"); + operation.setResponses(responses); + pathItem.get(operation); + paths.addPathItem("/sample/users", pathItem); + oai.setPaths(paths); + + OpenAPIConfig openAPIConfig = new OpenAPIConfig () { + + @Override + public String getFilterClass() { + return null; + } + + @Override + public Set getIgnoredClasses() { + return null; + } + + @Override + public OpenAPI getOpenAPI() { + return oai; + } + + @Override + public Map getOptions() { + return null; + } + + @Override + public String getReaderClass() { + return null; + } + + @Override + public Set getResourceClasses() { + return null; + } + + @Override + public Set getResourcePackages() { + return null; + } + + @Override + public String getScannerClass() { + return null; + } + + @Override + public boolean isScanDisabled() { + return false; + } + }; + return openAPIConfig; + } } From c0df270243b12d61a90e2568200fbc072bed70b3 Mon Sep 17 00:00:00 2001 From: Janarthanan Date: Thu, 10 Aug 2017 14:13:51 -0400 Subject: [PATCH 7/8] added params --- .../swagger/sample/servlet/SampleServlet.java | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java b/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java index 736e78df..339ead53 100644 --- a/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java +++ b/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java @@ -119,20 +119,59 @@ public OpenAPIConfig build(Map arg0) { Operation operation = new Operation(); operation.setDescription("Resource to get a user"); - ApiResponses responses = new ApiResponses(); - ApiResponse item = new ApiResponse(); + + ApiResponses responses = new ApiResponses(); + + ApiResponse item = new ApiResponse(); item.setDescription("Successful"); - Content content = new Content(); - MediaType mediaType = new MediaType(); - Schema schema = new Schema(); + + Content content = new Content(); + MediaType mediaType = new MediaType(); + + Schema schema = new Schema(); schema.set$ref("#/components/schemas/User"); - mediaType.setSchema(schema); - content.addMediaType("application/json", mediaType); - item.setContent(content); - operation.setDescription("Resource to get a user"); + mediaType.setSchema(schema); + content.addMediaType("application/json", mediaType); + + item.setContent(content); + operation.setResponses(responses); - pathItem.get(operation); + + List parameters = new ArrayList(); + parameters.add(new Parameter() + .name("name") + .required(true) + .in("query") + .description("Name of the user") + .schema(new Schema() + .type("string"))); + parameters.add(new Parameter() + .name("id") + .required(true) + .in("query") + .description("Id of the user") + .schema(new Schema() + .type("integer") + .format("int32"))); + parameters.add(new Parameter() + .name("email") + .required(true) + .in("query") + .description("Email of the user") + .schema(new Schema() + .type("string"))); + parameters.add(new Parameter() + .name("age") + .required(true) + .in("query") + .description("Age of the user") + .schema(new Schema() + .type("integer") + .format("int32"))); + operation.setParameters(parameters); + + pathItem.get(operation); paths.addPathItem("/sample/users", pathItem); oai.setPaths(paths); From 77f14c1e265d6df4119df6013ca36a6ec2852f83 Mon Sep 17 00:00:00 2001 From: Janarthanan Date: Thu, 10 Aug 2017 14:15:29 -0400 Subject: [PATCH 8/8] fixed indentations --- .../io/swagger/sample/servlet/SampleServlet.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java b/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java index 339ead53..822dae5d 100644 --- a/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java +++ b/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java @@ -140,12 +140,12 @@ public OpenAPIConfig build(Map arg0) { List parameters = new ArrayList(); parameters.add(new Parameter() - .name("name") - .required(true) - .in("query") - .description("Name of the user") - .schema(new Schema() - .type("string"))); + .name("name") + .required(true) + .in("query") + .description("Name of the user") + .schema(new Schema() + .type("string"))); parameters.add(new Parameter() .name("id") .required(true)