[Java][jersey2] Fix Java compiler warnings (#6605)

* Mustache template should use invokerPackage tag to generate import

* fix typo, fix script issue, add log statement for troubleshooting

* Add java jersey2 samples with OpenAPI doc that has HTTP signature security scheme

* Add sample for Java jersey2 and HTTP signature scheme

* Add unit test for oneOf schema deserialization

* Add unit test for oneOf schema deserialization

* Add log statements

* Add profile for jersey2

* Temporarily disable unit test

* Temporarily disable unit test

* support for discriminator in jersey2

* fix typo in pom.xml

* disable unit test because jersey2 deserialization is broken

* disable unit test because jersey2 deserialization is broken

* fix duplicate jersey2 samples

* fix duplicate jersey2 samples

* Add code comments

* fix duplicate artifact id

* fix duplicate jersey2 samples

* run samples scripts

* resolve merge conflicts

* Add unit tests

* fix unit tests

* continue implementation of discriminator lookup

* throw deserialization exception when value is null and schema does not allow null value

* continue implementation of compose schema

* continue implementation of compose schema

* continue implementation of compose schema

* Add more unit tests

* Add unit tests for anyOf

* Add unit tests

* [java][jersey2] Add support for discriminator, fix nullable typo and nullable deserialization (#6495)

* Mustache template should use invokerPackage tag to generate import

* fix typo, fix script issue, add log statement for troubleshooting

* Add java jersey2 samples with OpenAPI doc that has HTTP signature security scheme

* Add sample for Java jersey2 and HTTP signature scheme

* Add unit test for oneOf schema deserialization

* Add unit test for oneOf schema deserialization

* Add log statements

* Add profile for jersey2

* Temporarily disable unit test

* Temporarily disable unit test

* support for discriminator in jersey2

* fix typo in pom.xml

* disable unit test because jersey2 deserialization is broken

* disable unit test because jersey2 deserialization is broken

* fix duplicate jersey2 samples

* fix duplicate jersey2 samples

* Add code comments

* fix duplicate artifact id

* fix duplicate jersey2 samples

* run samples scripts

* resolve merge conflicts

* Add unit tests

* fix unit tests

* continue implementation of discriminator lookup

* throw deserialization exception when value is null and schema does not allow null value

* continue implementation of compose schema

* continue implementation of compose schema

* continue implementation of compose schema

* Add more unit tests

* Add unit tests for anyOf

* Add unit tests

Co-authored-by: Vikrant Balyan (vvb) <vvb@cisco.com>

* update samples

* add tests to oas3 java jersey2 petstore

* Fix 'method too big' error with generated code

* resolve merge conflicts

* comment out jersey2 ensure uptodate

* fix compiler warnings

* Jersey2 supports additional properties with composed schema (#6523)

* Mustache template should use invokerPackage tag to generate import

* fix typo, fix script issue, add log statement for troubleshooting

* Add java jersey2 samples with OpenAPI doc that has HTTP signature security scheme

* Add sample for Java jersey2 and HTTP signature scheme

* Add unit test for oneOf schema deserialization

* Add unit test for oneOf schema deserialization

* Add log statements

* Add profile for jersey2

* Temporarily disable unit test

* Temporarily disable unit test

* support for discriminator in jersey2

* fix typo in pom.xml

* disable unit test because jersey2 deserialization is broken

* disable unit test because jersey2 deserialization is broken

* fix duplicate jersey2 samples

* fix duplicate jersey2 samples

* Add code comments

* fix duplicate artifact id

* fix duplicate jersey2 samples

* run samples scripts

* resolve merge conflicts

* Add unit tests

* fix unit tests

* continue implementation of discriminator lookup

* throw deserialization exception when value is null and schema does not allow null value

* continue implementation of compose schema

* continue implementation of compose schema

* continue implementation of compose schema

* Add more unit tests

* Add unit tests for anyOf

* Add unit tests

* Set supportsAdditionalPropertiesWithComposedSchema to true for Java jersey2

* Support additional properties as nested field

* Support additional properties as nested field

* add code comments

* add customer deserializer

* Fix 'method too big' error with generated code

* resolve merge conflicts

Co-authored-by: Vikrant Balyan (vvb) <vvb@cisco.com>

* [Jersey2] Fix code generation of 'registerDiscriminator' method for large models (#6535)

* Mustache template should use invokerPackage tag to generate import

* fix typo, fix script issue, add log statement for troubleshooting

* Add java jersey2 samples with OpenAPI doc that has HTTP signature security scheme

* Add sample for Java jersey2 and HTTP signature scheme

* Add unit test for oneOf schema deserialization

* Add unit test for oneOf schema deserialization

* Add log statements

* Add profile for jersey2

* Temporarily disable unit test

* Temporarily disable unit test

* support for discriminator in jersey2

* fix typo in pom.xml

* disable unit test because jersey2 deserialization is broken

* disable unit test because jersey2 deserialization is broken

* fix duplicate jersey2 samples

* fix duplicate jersey2 samples

* Add code comments

* fix duplicate artifact id

* fix duplicate jersey2 samples

* run samples scripts

* resolve merge conflicts

* Add unit tests

* fix unit tests

* continue implementation of discriminator lookup

* throw deserialization exception when value is null and schema does not allow null value

* continue implementation of compose schema

* continue implementation of compose schema

* continue implementation of compose schema

* Add more unit tests

* Add unit tests for anyOf

* Add unit tests

* Fix 'method too big' error with generated code

* resolve merge conflicts

Co-authored-by: Vikrant Balyan (vvb) <vvb@cisco.com>

* Add unit test for date time

* Add unit test for date time

* update samples

* comment out tests

* support additional properties in serialize and deserialize

* add discriminator lookup

* remove oneof/anyof logic in apilcient

* add serializer to mammal.java

* add serialize to oneOf model

* add serializer to anyof model

* comment out test cases that are subject to further discussion

* add back files

* update configs, samples

* resolve merge conflicts

Co-authored-by: Vikrant Balyan (vvb) <vvb@cisco.com>
Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
Sebastien Rosset
2020-06-09 20:52:38 -07:00
committed by GitHub
parent 0b561d6075
commit 4bbe3cdbc9
29 changed files with 161 additions and 103 deletions

View File

@@ -59,10 +59,10 @@ public class JSON implements ContextResolver<ObjectMapper> {
* @param node The input data.
* @param modelClass The class that contains the discriminator mappings.
*/
public static Class getClassForElement(JsonNode node, Class modelClass) {
public static Class<?> getClassForElement(JsonNode node, Class<?> modelClass) {
ClassDiscriminatorMapping cdm = modelDiscriminators.get(modelClass);
if (cdm != null) {
return cdm.getClassForElement(node, new HashSet<Class>());
return cdm.getClassForElement(node, new HashSet<Class<?>>());
}
return null;
}
@@ -72,17 +72,17 @@ public class JSON implements ContextResolver<ObjectMapper> {
*/
private static class ClassDiscriminatorMapping {
// The model class name.
Class modelClass;
Class<?> modelClass;
// The name of the discriminator property.
String discriminatorName;
// The discriminator mappings for a model class.
Map<String, Class> discriminatorMappings;
Map<String, Class<?>> discriminatorMappings;
// Constructs a new class discriminator.
ClassDiscriminatorMapping(Class cls, String propertyName, Map<String, Class> mappings) {
ClassDiscriminatorMapping(Class<?> cls, String propertyName, Map<String, Class<?>> mappings) {
modelClass = cls;
discriminatorName = propertyName;
discriminatorMappings = new HashMap<String, Class>();
discriminatorMappings = new HashMap<String, Class<?>>();
if (mappings != null) {
discriminatorMappings.putAll(mappings);
}
@@ -118,7 +118,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
* @param node The input data.
* @param visitedClasses The set of classes that have already been visited.
*/
Class getClassForElement(JsonNode node, Set<Class> visitedClasses) {
Class<?> getClassForElement(JsonNode node, Set<Class<?>> visitedClasses) {
if (visitedClasses.contains(modelClass)) {
// Class has already been visited.
return null;
@@ -128,11 +128,11 @@ public class JSON implements ContextResolver<ObjectMapper> {
if (discrValue == null) {
return null;
}
Class cls = discriminatorMappings.get(discrValue);
Class<?> cls = discriminatorMappings.get(discrValue);
// It may not be sufficient to return this cls directly because that target class
// may itself be a composed schema, possibly with its own discriminator.
visitedClasses.add(modelClass);
for (Class childClass : discriminatorMappings.values()) {
for (Class<?> childClass : discriminatorMappings.values()) {
ClassDiscriminatorMapping childCdm = modelDiscriminators.get(childClass);
if (childCdm == null) {
continue;
@@ -145,7 +145,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
}
if (childCdm != null) {
// Recursively traverse the discriminator mappings.
Class childDiscr = childCdm.getClassForElement(node, visitedClasses);
Class<?> childDiscr = childCdm.getClassForElement(node, visitedClasses);
if (childDiscr != null) {
return childDiscr;
}
@@ -164,7 +164,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
* @param modelClass A OpenAPI model class.
* @param inst The instance object.
*/
public static boolean isInstanceOf(Class modelClass, Object inst, Set<Class> visitedClasses) {
public static boolean isInstanceOf(Class<?> modelClass, Object inst, Set<Class<?>> visitedClasses) {
if (modelClass.isInstance(inst)) {
// This handles the 'allOf' use case with single parent inheritance.
return true;
@@ -191,12 +191,12 @@ public class JSON implements ContextResolver<ObjectMapper> {
/**
* A map of discriminators for all model classes.
*/
private static Map<Class, ClassDiscriminatorMapping> modelDiscriminators = new HashMap<Class, ClassDiscriminatorMapping>();
private static Map<Class<?>, ClassDiscriminatorMapping> modelDiscriminators = new HashMap<Class<?>, ClassDiscriminatorMapping>();
/**
* A map of oneOf/anyOf descendants for each model class.
*/
private static Map<Class, Map<String, GenericType>> modelDescendants = new HashMap<Class, Map<String, GenericType>>();
private static Map<Class<?>, Map<String, GenericType>> modelDescendants = new HashMap<Class<?>, Map<String, GenericType>>();
/**
* Register a model class discriminator.
@@ -205,7 +205,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
* @param discriminatorPropertyName the name of the discriminator property
* @param mappings a map with the discriminator mappings.
*/
public static void registerDiscriminator(Class modelClass, String discriminatorPropertyName, Map<String, Class> mappings) {
public static void registerDiscriminator(Class<?> modelClass, String discriminatorPropertyName, Map<String, Class<?>> mappings) {
ClassDiscriminatorMapping m = new ClassDiscriminatorMapping(modelClass, discriminatorPropertyName, mappings);
modelDiscriminators.put(modelClass, m);
}
@@ -216,7 +216,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
* @param modelClass the model class
* @param descendants a map of oneOf/anyOf descendants.
*/
public static void registerDescendants(Class modelClass, Map<String, GenericType> descendants) {
public static void registerDescendants(Class<?> modelClass, Map<String, GenericType> descendants) {
modelDescendants.put(modelClass, descendants);
}

View File

@@ -144,7 +144,7 @@ public class Animal {
static {
// Initialize and register the discriminator mappings.
Map<String, Class> mappings = new HashMap<String, Class>();
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
mappings.put("BigCat", BigCat.class);
mappings.put("Cat", Cat.class);
mappings.put("Dog", Dog.class);

View File

@@ -152,7 +152,7 @@ public class BigCat extends Cat {
static {
// Initialize and register the discriminator mappings.
Map<String, Class> mappings = new HashMap<String, Class>();
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
mappings.put("BigCat", BigCat.class);
JSON.registerDiscriminator(BigCat.class, "className", mappings);
}

View File

@@ -115,7 +115,7 @@ public class Cat extends Animal {
static {
// Initialize and register the discriminator mappings.
Map<String, Class> mappings = new HashMap<String, Class>();
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
mappings.put("BigCat", BigCat.class);
mappings.put("Cat", Cat.class);
JSON.registerDiscriminator(Cat.class, "className", mappings);

View File

@@ -113,7 +113,7 @@ public class Dog extends Animal {
static {
// Initialize and register the discriminator mappings.
Map<String, Class> mappings = new HashMap<String, Class>();
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
mappings.put("Dog", Dog.class);
JSON.registerDiscriminator(Dog.class, "className", mappings);
}

View File

@@ -3,7 +3,9 @@ package org.openapitools.client;
import org.openapitools.client.model.Order;
import java.lang.Exception;
import java.util.Date;
import java.util.TimeZone;
import java.text.SimpleDateFormat;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
@@ -32,6 +34,33 @@ public class JSONTest {
assertEquals(dateStr, dateFormat.format(o.getShipDate()));
}
@Test
public void testRFC3339DateFormatDate() throws Exception {
{
String dateStr = "2011-01-18 00:00:00.0Z";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = sdf.parse(dateStr);
RFC3339DateFormat df = new RFC3339DateFormat();
StringBuffer sb = new StringBuffer();
String s = df.format(date);
System.out.println("DATE: " + s);
assertEquals("2011-01-18T00:00:00.000Z", s);
}
{
String dateStr = "2011-01-18 00:00:00.0";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
Date date = sdf.parse(dateStr);
RFC3339DateFormat df = new RFC3339DateFormat();
StringBuffer sb = new StringBuffer();
String s = df.format(date);
assertEquals("2011-01-18T08:00:00.000Z", s);
}
}
@Test
public void testCustomDate() throws Exception {
final DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Etc/GMT+2"));