[Java] Fix serialization of the discriminator field when using GSON (#7075)

* set discriminator on object construction...

* regenerate all java samples

* run bin/java-msf4j-petstore-server.sh

* remove extra newline
This commit is contained in:
craffael 2018-01-07 16:10:32 +01:00 committed by William Cheng
parent ea3d039717
commit 9a284776d8
14 changed files with 1879 additions and 2021 deletions

View File

@ -67,6 +67,13 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
{{/isContainer}}
{{/vars}}
{{#gson}}
{{#discriminator}}
public {{classname}}() {
this.{{discriminator}} = this.getClass().getSimpleName();
}
{{/discriminator}}
{{/gson}}
{{#vars}}
{{^isReadOnly}}
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {

View File

@ -37,6 +37,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("DELETE /pet/{petId}")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
"api_key: {apiKey}"
})
@ -50,6 +51,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("GET /pet/findByStatus?status={status}")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
List<Pet> findPetsByStatus(@Param("status") List<String> status);
@ -71,6 +73,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("GET /pet/findByStatus?status={status}")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
List<Pet> findPetsByStatus(@QueryMap(encoded=true) Map<String, Object> queryParams);
@ -94,6 +97,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("GET /pet/findByTags?tags={tags}")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
List<Pet> findPetsByTags(@Param("tags") List<String> tags);
@ -115,6 +119,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("GET /pet/findByTags?tags={tags}")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
List<Pet> findPetsByTags(@QueryMap(encoded=true) Map<String, Object> queryParams);
@ -138,6 +143,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("GET /pet/{petId}")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
Pet getPetById(@Param("petId") Long petId);

View File

@ -22,6 +22,7 @@ public interface StoreApi extends ApiClient.Api {
*/
@RequestLine("DELETE /store/order/{orderId}")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
void deleteOrder(@Param("orderId") String orderId);
@ -33,6 +34,7 @@ public interface StoreApi extends ApiClient.Api {
*/
@RequestLine("GET /store/inventory")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
Map<String, Integer> getInventory();
@ -45,6 +47,7 @@ public interface StoreApi extends ApiClient.Api {
*/
@RequestLine("GET /store/order/{orderId}")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
Order getOrderById(@Param("orderId") Long orderId);

View File

@ -58,6 +58,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("DELETE /user/{username}")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
void deleteUser(@Param("username") String username);
@ -70,6 +71,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("GET /user/{username}")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
User getUserByName(@Param("username") String username);
@ -83,6 +85,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("GET /user/login?username={username}&password={password}")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
String loginUser(@Param("username") String username, @Param("password") String password);
@ -105,6 +108,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("GET /user/login?username={username}&password={password}")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
String loginUser(@QueryMap(encoded=true) Map<String, Object> queryParams);
@ -130,6 +134,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("GET /user/logout")
@Headers({
"Content-Type: application/json",
"Accept: application/json",
})
void logoutUser();

View File

@ -13,6 +13,9 @@
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<licenses>
<license>
@ -33,26 +36,6 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.2.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@ -113,8 +96,7 @@
</goals>
<configuration>
<sources>
<source>
src/main/java</source>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
@ -126,8 +108,7 @@
</goals>
<configuration>
<sources>
<source>
src/test/java</source>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
@ -138,8 +119,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>
1.7</source>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
@ -266,7 +246,6 @@
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-core-version>1.5.15</swagger-core-version>
<jersey-version>2.6</jersey-version>
<commons_io_version>2.5</commons_io_version>

View File

@ -13,6 +13,9 @@
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<licenses>
<license>
@ -33,26 +36,6 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.2.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@ -113,8 +96,7 @@
</goals>
<configuration>
<sources>
<source>
src/main/java</source>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
@ -126,8 +108,7 @@
</goals>
<configuration>
<sources>
<source>
src/test/java</source>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
@ -138,8 +119,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>
1.8</source>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
@ -250,7 +230,6 @@
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-core-version>1.5.15</swagger-core-version>
<jersey-version>2.25.1</jersey-version>
<jackson-version>2.7.5</jackson-version>

View File

@ -13,6 +13,9 @@
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<licenses>
<license>
@ -33,26 +36,6 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.2.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@ -113,8 +96,7 @@
</goals>
<configuration>
<sources>
<source>
src/main/java</source>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
@ -126,8 +108,7 @@
</goals>
<configuration>
<sources>
<source>
src/test/java</source>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
@ -138,8 +119,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>
1.7</source>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
@ -256,7 +236,6 @@
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-core-version>1.5.15</swagger-core-version>
<jersey-version>2.25.1</jersey-version>
<jackson-version>2.6.4</jackson-version>

View File

@ -11,29 +11,12 @@
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.2.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@ -94,8 +77,7 @@
</goals>
<configuration>
<sources>
<source>
src/main/java</source>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
@ -107,8 +89,7 @@
</goals>
<configuration>
<sources>
<source>
src/test/java</source>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
@ -119,8 +100,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>
1.7</source>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
@ -206,7 +186,6 @@
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-core-version>1.5.15</swagger-core-version>
<resteasy-version>3.1.3.Final</resteasy-version>
<jackson-version>2.6.4</jackson-version>

View File

@ -13,6 +13,9 @@
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<licenses>
<license>
@ -33,26 +36,6 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.2.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@ -114,8 +97,7 @@
</goals>
<configuration>
<sources>
<source>
src/main/java</source>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
@ -127,8 +109,7 @@
</goals>
<configuration>
<sources>
<source>
src/test/java</source>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
@ -139,8 +120,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>
1.7</source>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

View File

@ -13,6 +13,9 @@
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<licenses>
<license>
@ -33,26 +36,6 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.2.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@ -114,8 +97,7 @@
</goals>
<configuration>
<sources>
<source>
src/main/java</source>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
@ -127,8 +109,7 @@
</goals>
<configuration>
<sources>
<source>
src/test/java</source>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
@ -139,8 +120,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>
1.7</source>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

View File

@ -13,6 +13,9 @@
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<licenses>
<license>
@ -33,26 +36,6 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.2.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@ -113,8 +96,7 @@
</goals>
<configuration>
<sources>
<source>
src/main/java</source>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
@ -126,8 +108,7 @@
</goals>
<configuration>
<sources>
<source>
src/test/java</source>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
@ -232,7 +213,6 @@
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-core-version>1.5.15</swagger-core-version>
<retrofit-version>1.9.0</retrofit-version>
<okhttp-version>2.7.5</okhttp-version>

View File

@ -13,6 +13,9 @@
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<licenses>
<license>
@ -33,26 +36,6 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.2.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@ -114,8 +97,7 @@
</goals>
<configuration>
<sources>
<source>
src/main/java</source>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
@ -127,8 +109,7 @@
</goals>
<configuration>
<sources>
<source>
src/test/java</source>
<source>src/test/java</source>
</sources>
</configuration>
</execution>

View File

@ -109,11 +109,11 @@ paths:
type: "array"
items:
type: "string"
default: "available"
enum:
- "available"
- "pending"
- "sold"
default: "available"
collectionFormat: "csv"
responses:
200:
@ -650,10 +650,10 @@ paths:
type: "array"
items:
type: "string"
default: "$"
enum:
- ">"
- "$"
default: "$"
- name: "enum_form_string"
in: "formData"
description: "Form parameter enum test (string)"
@ -671,10 +671,10 @@ paths:
type: "array"
items:
type: "string"
default: "$"
enum:
- ">"
- "$"
default: "$"
- name: "enum_header_string"
in: "header"
description: "Header parameter enum test (string)"
@ -692,10 +692,10 @@ paths:
type: "array"
items:
type: "string"
default: "$"
enum:
- ">"
- "$"
default: "$"
- name: "enum_query_string"
in: "query"
description: "Query parameter enum test (string)"

View File

@ -2,51 +2,51 @@
# This file defines all application routes (Higher priority routes first)
# ~~~~
GET /api controllers.ApiDocController.api
GET /api controllers.ApiDocController.api
#Functions for AnotherFake API
PATCH /v2/another-fake/dummy controllers.AnotherFakeApiController.testSpecialTags()
#Functions for AnotherFake API
PATCH /v2/another-fake/dummy controllers.AnotherFakeApiController.testSpecialTags()
#Functions for Fake API
POST /v2/fake/outer/boolean controllers.FakeApiController.fakeOuterBooleanSerialize()
POST /v2/fake/outer/composite controllers.FakeApiController.fakeOuterCompositeSerialize()
POST /v2/fake/outer/number controllers.FakeApiController.fakeOuterNumberSerialize()
POST /v2/fake/outer/string controllers.FakeApiController.fakeOuterStringSerialize()
PATCH /v2/fake controllers.FakeApiController.testClientModel()
POST /v2/fake controllers.FakeApiController.testEndpointParameters()
GET /v2/fake controllers.FakeApiController.testEnumParameters()
POST /v2/fake/inline-additionalProperties controllers.FakeApiController.testInlineAdditionalProperties()
GET /v2/fake/jsonFormData controllers.FakeApiController.testJsonFormData()
#Functions for Fake API
POST /v2/fake/outer/boolean controllers.FakeApiController.fakeOuterBooleanSerialize()
POST /v2/fake/outer/composite controllers.FakeApiController.fakeOuterCompositeSerialize()
POST /v2/fake/outer/number controllers.FakeApiController.fakeOuterNumberSerialize()
POST /v2/fake/outer/string controllers.FakeApiController.fakeOuterStringSerialize()
PATCH /v2/fake controllers.FakeApiController.testClientModel()
POST /v2/fake controllers.FakeApiController.testEndpointParameters()
GET /v2/fake controllers.FakeApiController.testEnumParameters()
POST /v2/fake/inline-additionalProperties controllers.FakeApiController.testInlineAdditionalProperties()
GET /v2/fake/jsonFormData controllers.FakeApiController.testJsonFormData()
#Functions for FakeClassnameTags123 API
PATCH /v2/fake_classname_test controllers.FakeClassnameTags123ApiController.testClassname()
#Functions for FakeClassnameTags123 API
PATCH /v2/fake_classname_test controllers.FakeClassnameTags123ApiController.testClassname()
#Functions for Pet API
POST /v2/pet controllers.PetApiController.addPet()
DELETE /v2/pet/:petId controllers.PetApiController.deletePet(petId: Long)
GET /v2/pet/findByStatus controllers.PetApiController.findPetsByStatus()
GET /v2/pet/findByTags controllers.PetApiController.findPetsByTags()
GET /v2/pet/:petId controllers.PetApiController.getPetById(petId: Long)
PUT /v2/pet controllers.PetApiController.updatePet()
POST /v2/pet/:petId controllers.PetApiController.updatePetWithForm(petId: Long)
POST /v2/pet/:petId/uploadImage controllers.PetApiController.uploadFile(petId: Long)
#Functions for Pet API
POST /v2/pet controllers.PetApiController.addPet()
DELETE /v2/pet/:petId controllers.PetApiController.deletePet(petId: Long)
GET /v2/pet/findByStatus controllers.PetApiController.findPetsByStatus()
GET /v2/pet/findByTags controllers.PetApiController.findPetsByTags()
GET /v2/pet/:petId controllers.PetApiController.getPetById(petId: Long)
PUT /v2/pet controllers.PetApiController.updatePet()
POST /v2/pet/:petId controllers.PetApiController.updatePetWithForm(petId: Long)
POST /v2/pet/:petId/uploadImage controllers.PetApiController.uploadFile(petId: Long)
#Functions for Store API
DELETE /v2/store/order/:orderId controllers.StoreApiController.deleteOrder(orderId: String)
GET /v2/store/inventory controllers.StoreApiController.getInventory()
GET /v2/store/order/:orderId controllers.StoreApiController.getOrderById(orderId: Long)
POST /v2/store/order controllers.StoreApiController.placeOrder()
#Functions for Store API
DELETE /v2/store/order/:orderId controllers.StoreApiController.deleteOrder(orderId: String)
GET /v2/store/inventory controllers.StoreApiController.getInventory()
GET /v2/store/order/:orderId controllers.StoreApiController.getOrderById(orderId: Long)
POST /v2/store/order controllers.StoreApiController.placeOrder()
#Functions for User API
POST /v2/user controllers.UserApiController.createUser()
POST /v2/user/createWithArray controllers.UserApiController.createUsersWithArrayInput()
POST /v2/user/createWithList controllers.UserApiController.createUsersWithListInput()
DELETE /v2/user/:username controllers.UserApiController.deleteUser(username: String)
GET /v2/user/:username controllers.UserApiController.getUserByName(username: String)
GET /v2/user/login controllers.UserApiController.loginUser()
GET /v2/user/logout controllers.UserApiController.logoutUser()
PUT /v2/user/:username controllers.UserApiController.updateUser(username: String)
#Functions for User API
POST /v2/user controllers.UserApiController.createUser()
POST /v2/user/createWithArray controllers.UserApiController.createUsersWithArrayInput()
POST /v2/user/createWithList controllers.UserApiController.createUsersWithListInput()
DELETE /v2/user/:username controllers.UserApiController.deleteUser(username: String)
GET /v2/user/:username controllers.UserApiController.getUserByName(username: String)
GET /v2/user/login controllers.UserApiController.loginUser()
GET /v2/user/logout controllers.UserApiController.logoutUser()
PUT /v2/user/:username controllers.UserApiController.updateUser(username: String)
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(file)