Skip to content

Commit 629608c

Browse files
fuj1g0nwing328
authored andcommitted
[jaxrs-spec*] samples should be tested. repair import and dependency. (#755)
* sample server projects "jaxrs-spec", "jaxrs-spec-interface", and "jaxrs-spec-interface-response" should be tested * update jax-rs api to 2.1, in which @patch annotation is available add jackson annotation dependency * add joda-time to dependency * modify mustache template to add @JsonCreate, @jsonvalue import * fix return type of enum value() method * add InputStream import * Attachment class is in apache cxf. spec should not depend on it * re-generate sample jaxrs-spec, jaxrs-spec-interface, and jaxrs-spec-interface-response
1 parent e143214 commit 629608c

131 files changed

Lines changed: 830 additions & 194 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import javax.ws.rs.core.Response;
88

99
import io.swagger.annotations.*;
1010

11+
import java.io.InputStream;
1112
import java.util.Map;
1213
import java.util.List;
1314
{{#useBeanValidation}}import javax.validation.constraints.*;

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/enumClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public enum {{datatypeWithEnum}} {
1111
value = v;
1212
}
1313

14-
public String value() {
14+
public {{dataType}} value() {
1515
return value;
1616
}
1717

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
{{#isFormParam}}{{^isFile}}@FormParam(value = "{{baseName}}") {{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}} @FormParam(value = "{{baseName}}") InputStream {{paramName}}InputStream,
2-
@FormParam(value = "{{baseName}}") Attachment {{paramName}}Detail{{/isFile}}{{/isFormParam}}
1+
{{#isFormParam}}{{^isFile}}@FormParam(value = "{{baseName}}") {{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}} @FormParam(value = "{{baseName}}") InputStream {{paramName}}InputStream{{/isFile}}{{/isFormParam}}

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/model.mustache

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import javax.validation.Valid;
1111
{{/useBeanValidation}}
1212

1313
{{#models}}
14-
{{#model}}{{#description}}
15-
/**
16-
* {{description}}
17-
**/{{/description}}
14+
{{#model}}
1815
{{#isEnum}}
1916
{{>enumOuterClass}}
2017
{{/isEnum}}

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustache

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import io.swagger.annotations.*;
22
import java.util.Objects;
33
import com.fasterxml.jackson.annotation.JsonProperty;
4-
{{#description}}@ApiModel(description = "{{{description}}}"){{/description}}
4+
import com.fasterxml.jackson.annotation.JsonCreator;
5+
import com.fasterxml.jackson.annotation.JsonValue;
56

7+
{{#description}}
8+
/**
9+
* {{description}}
10+
**/{{/description}}
11+
{{#description}}@ApiModel(description = "{{{description}}}"){{/description}}
612
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
713
{{#vars}}{{#isEnum}}{{^isContainer}}
814

pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,42 @@
715715
<module>samples/server/petstore/jaxrs/jersey1</module>
716716
</modules>
717717
</profile>
718+
<profile>
719+
<id>jaxrs-spec</id>
720+
<activation>
721+
<property>
722+
<name>env</name>
723+
<value>java</value>
724+
</property>
725+
</activation>
726+
<modules>
727+
<module>samples/server/petstore/jaxrs-spec</module>
728+
</modules>
729+
</profile>
730+
<profile>
731+
<id>jaxrs-spec-interface</id>
732+
<activation>
733+
<property>
734+
<name>env</name>
735+
<value>java</value>
736+
</property>
737+
</activation>
738+
<modules>
739+
<module>samples/server/petstore/jaxrs-spec-interface</module>
740+
</modules>
741+
</profile>
742+
<profile>
743+
<id>jaxrs-spec-interface-response</id>
744+
<activation>
745+
<property>
746+
<name>env</name>
747+
<value>java</value>
748+
</property>
749+
</activation>
750+
<modules>
751+
<module>samples/server/petstore/jaxrs-spec-interface-response</module>
752+
</modules>
753+
</profile>
718754
<profile>
719755
<id>typescript-fetch-client-tests-default</id>
720756
<activation>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.1-SNAPSHOT
1+
3.2.0-SNAPSHOT

samples/server/petstore/jaxrs-spec-interface-response/pom.xml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,32 @@
1313
<artifactId>maven-jar-plugin</artifactId>
1414
<version>2.2</version>
1515
</plugin>
16+
<plugin>
17+
<groupId>org.codehaus.mojo</groupId>
18+
<artifactId>build-helper-maven-plugin</artifactId>
19+
<version>1.9.1</version>
20+
<executions>
21+
<execution>
22+
<id>add-source</id>
23+
<phase>generate-sources</phase>
24+
<goals>
25+
<goal>add-source</goal>
26+
</goals>
27+
<configuration>
28+
<sources>
29+
<source>src/gen/java</source>
30+
</sources>
31+
</configuration>
32+
</execution>
33+
</executions>
34+
</plugin>
1635
</plugins>
1736
</build>
1837
<dependencies>
1938
<dependency>
2039
<groupId>javax.ws.rs</groupId>
2140
<artifactId>javax.ws.rs-api</artifactId>
22-
<version>2.0</version>
41+
<version>2.1</version>
2342
<scope>provided</scope>
2443
</dependency>
2544
<dependency>
@@ -28,6 +47,18 @@
2847
<scope>provided</scope>
2948
<version>1.5.3</version>
3049
</dependency>
50+
<dependency>
51+
<groupId>com.fasterxml.jackson.core</groupId>
52+
<artifactId>jackson-annotations</artifactId>
53+
<version>${jackson-version}</version>
54+
<scope>provided</scope>
55+
</dependency>
56+
<dependency>
57+
<groupId>joda-time</groupId>
58+
<artifactId>joda-time</artifactId>
59+
<version>${jodatime-version}</version>
60+
<scope>provided</scope>
61+
</dependency>
3162
<dependency>
3263
<groupId>junit</groupId>
3364
<artifactId>junit</artifactId>
@@ -44,5 +75,7 @@
4475
</dependencies>
4576
<properties>
4677
<junit-version>4.8.1</junit-version>
78+
<jackson-version>2.8.9</jackson-version>
79+
<jodatime-version>2.9.9</jodatime-version>
4780
</properties>
4881
</project>

samples/server/petstore/jaxrs-spec-interface-response/src/gen/java/org/openapitools/api/AnotherFakeApi.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import io.swagger.annotations.*;
99

10+
import java.io.InputStream;
1011
import java.util.Map;
1112
import java.util.List;
1213
import javax.validation.constraints.*;
@@ -20,8 +21,8 @@ public interface AnotherFakeApi {
2021
@Path("/dummy")
2122
@Consumes({ "application/json" })
2223
@Produces({ "application/json" })
23-
@ApiOperation(value = "To test special tags", notes = "To test special tags", tags={ "$another-fake?" })
24+
@ApiOperation(value = "To test special tags", notes = "To test special tags and operation ID starting with number", tags={ "$another-fake?" })
2425
@ApiResponses(value = {
2526
@ApiResponse(code = 200, message = "successful operation", response = Client.class) })
26-
Response testSpecialTags(@Valid Client client);
27+
Response call123testSpecialTags(@Valid Client client);
2728
}

samples/server/petstore/jaxrs-spec-interface-response/src/gen/java/org/openapitools/api/FakeApi.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import org.openapitools.model.Client;
55
import java.util.Date;
66
import java.io.File;
7+
import org.openapitools.model.FileSchemaTestClass;
78
import org.joda.time.LocalDate;
89
import java.util.Map;
10+
import org.openapitools.model.ModelApiResponse;
911
import org.openapitools.model.OuterComposite;
1012
import org.openapitools.model.User;
1113

@@ -14,6 +16,7 @@
1416

1517
import io.swagger.annotations.*;
1618

19+
import java.io.InputStream;
1720
import java.util.Map;
1821
import java.util.List;
1922
import javax.validation.constraints.*;
@@ -55,6 +58,14 @@ public interface FakeApi {
5558
@ApiResponse(code = 200, message = "Output string", response = String.class) })
5659
Response fakeOuterStringSerialize(@Valid String body);
5760

61+
@PUT
62+
@Path("/body-with-file-schema")
63+
@Consumes({ "application/json" })
64+
@ApiOperation(value = "", notes = "For this test, the body for this request much reference a schema named `File`.", tags={ "fake", })
65+
@ApiResponses(value = {
66+
@ApiResponse(code = 200, message = "Success", response = Void.class) })
67+
Response testBodyWithFileSchema(@Valid FileSchemaTestClass fileSchemaTestClass);
68+
5869
@PUT
5970
@Path("/body-with-query-params")
6071
@Consumes({ "application/json" })
@@ -79,8 +90,7 @@ public interface FakeApi {
7990
@ApiResponses(value = {
8091
@ApiResponse(code = 400, message = "Invalid username supplied", response = Void.class),
8192
@ApiResponse(code = 404, message = "User not found", response = Void.class) })
82-
Response testEndpointParameters(@FormParam(value = "number") BigDecimal number,@FormParam(value = "double") Double _double,@FormParam(value = "pattern_without_delimiter") String patternWithoutDelimiter,@FormParam(value = "byte") byte[] _byte,@FormParam(value = "integer") Integer integer,@FormParam(value = "int32") Integer int32,@FormParam(value = "int64") Long int64,@FormParam(value = "float") Float _float,@FormParam(value = "string") String string, @FormParam(value = "binary") InputStream binaryInputStream,
83-
@FormParam(value = "binary") Attachment binaryDetail,@FormParam(value = "date") LocalDate date,@FormParam(value = "dateTime") Date dateTime,@FormParam(value = "password") String password,@FormParam(value = "callback") String paramCallback);
93+
Response testEndpointParameters(@FormParam(value = "number") BigDecimal number,@FormParam(value = "double") Double _double,@FormParam(value = "pattern_without_delimiter") String patternWithoutDelimiter,@FormParam(value = "byte") byte[] _byte,@FormParam(value = "integer") Integer integer,@FormParam(value = "int32") Integer int32,@FormParam(value = "int64") Long int64,@FormParam(value = "float") Float _float,@FormParam(value = "string") String string, @FormParam(value = "binary") InputStream binaryInputStream,@FormParam(value = "date") LocalDate date,@FormParam(value = "dateTime") Date dateTime,@FormParam(value = "password") String password,@FormParam(value = "callback") String paramCallback);
8494

8595
@GET
8696
@Consumes({ "application/x-www-form-urlencoded" })
@@ -101,8 +111,22 @@ Response testEndpointParameters(@FormParam(value = "number") BigDecimal number,
101111
@GET
102112
@Path("/jsonFormData")
103113
@Consumes({ "application/x-www-form-urlencoded" })
104-
@ApiOperation(value = "test json serialization of form data", notes = "", tags={ "fake" })
114+
@ApiOperation(value = "test json serialization of form data", notes = "", tags={ "fake", })
105115
@ApiResponses(value = {
106116
@ApiResponse(code = 200, message = "successful operation", response = Void.class) })
107117
Response testJsonFormData(@FormParam(value = "param") String param,@FormParam(value = "param2") String param2);
118+
119+
@POST
120+
@Path("/{petId}/uploadImageWithRequiredFile")
121+
@Consumes({ "multipart/form-data" })
122+
@Produces({ "application/json" })
123+
@ApiOperation(value = "uploads an image (required)", notes = "", authorizations = {
124+
@Authorization(value = "petstore_auth", scopes = {
125+
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
126+
@AuthorizationScope(scope = "read:pets", description = "read your pets")
127+
})
128+
}, tags={ "pet" })
129+
@ApiResponses(value = {
130+
@ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) })
131+
Response uploadFileWithRequiredFile(@PathParam("petId") @ApiParam("ID of pet to update") Long petId, @FormParam(value = "requiredFile") InputStream requiredFileInputStream,@FormParam(value = "additionalMetadata") String additionalMetadata);
108132
}

0 commit comments

Comments
 (0)