Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
41e97e6
Mustache template should use invokerPackage tag to generate import
sebastien-rosset May 13, 2020
1760f6a
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 13, 2020
3ae466e
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 13, 2020
b628667
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 13, 2020
4dc915c
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 14, 2020
7a207f6
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 16, 2020
776fba6
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 18, 2020
3fac434
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 19, 2020
a96c46b
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 20, 2020
1351fd0
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 21, 2020
ba65735
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 22, 2020
9a0b89e
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 22, 2020
4c84190
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 22, 2020
94ae683
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 22, 2020
aac9f5a
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 23, 2020
93baa3d
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 23, 2020
5c313b4
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 23, 2020
cda8898
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 23, 2020
1f7e5c1
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 24, 2020
bef435e
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 25, 2020
a9cad38
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 26, 2020
877ecfe
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 27, 2020
8c055f5
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 27, 2020
d64f421
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 28, 2020
4d0edfe
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 28, 2020
afeb701
fix typo, fix script issue, add log statement for troubleshooting
sebastien-rosset May 28, 2020
ed5c165
Add java jersey2 samples with OpenAPI doc that has HTTP signature sec…
sebastien-rosset May 28, 2020
7edcb06
Add sample for Java jersey2 and HTTP signature scheme
sebastien-rosset May 28, 2020
762bdb7
Add unit test for oneOf schema deserialization
sebastien-rosset May 29, 2020
c2c6364
Add unit test for oneOf schema deserialization
sebastien-rosset May 29, 2020
4b0d0ca
Add log statements
sebastien-rosset May 29, 2020
65076bb
Add profile for jersey2
sebastien-rosset May 29, 2020
60f98e1
Temporarily disable unit test
sebastien-rosset May 29, 2020
352497b
Temporarily disable unit test
sebastien-rosset May 29, 2020
476eb01
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 29, 2020
40bb8d9
Merge branch 'master' of github.com:CiscoM31/openapi-generator into j…
sebastien-rosset May 29, 2020
d227993
support for discriminator in jersey2
sebastien-rosset May 30, 2020
8ff6088
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 30, 2020
05d8718
Merge branch 'master' of github.com:CiscoM31/openapi-generator into j…
sebastien-rosset May 30, 2020
ac1a061
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 30, 2020
aa27b72
Merge branch 'master' of github.com:CiscoM31/openapi-generator into j…
sebastien-rosset May 30, 2020
22e6737
fix typo in pom.xml
sebastien-rosset May 30, 2020
1971f7d
Merge branch 'jersey2-misc-enhancements' of github.com:CiscoM31/opena…
sebastien-rosset May 30, 2020
90327fe
disable unit test because jersey2 deserialization is broken
sebastien-rosset May 30, 2020
5c52b6b
disable unit test because jersey2 deserialization is broken
sebastien-rosset May 30, 2020
38b8568
fix duplicate jersey2 samples
sebastien-rosset May 30, 2020
efec5a8
fix duplicate jersey2 samples
sebastien-rosset May 30, 2020
b3b4108
Merge branch 'jersey2-misc-enhancements' of github.com:CiscoM31/opena…
sebastien-rosset May 30, 2020
fac4991
Add code comments
sebastien-rosset May 30, 2020
057f1ca
fix duplicate artifact id
sebastien-rosset May 30, 2020
e94c5c8
fix duplicate jersey2 samples
sebastien-rosset May 30, 2020
99db107
run samples scripts
sebastien-rosset May 31, 2020
9671045
Merge branch 'jersey2-misc-enhancements' of github.com:CiscoM31/opena…
sebastien-rosset May 31, 2020
8579966
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 31, 2020
61e947e
Merge branch 'master' of github.com:CiscoM31/openapi-generator into j…
sebastien-rosset May 31, 2020
1cb05de
Merge branch 'master' of github.com:CiscoM31/openapi-generator into j…
sebastien-rosset May 31, 2020
20bd342
Merge branch 'jersey2-misc-enhancements' of github.com:CiscoM31/opena…
sebastien-rosset May 31, 2020
7c45925
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 31, 2020
cc61ec5
merge from master
sebastien-rosset May 31, 2020
cb6884c
resolve merge conflicts
sebastien-rosset May 31, 2020
7f52a53
Merge remote-tracking branch 'upstream/master'
vvb Jun 1, 2020
c123c91
Add unit tests
sebastien-rosset Jun 1, 2020
76d3348
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset Jun 1, 2020
797e779
Merge branch 'master' of github.com:CiscoM31/openapi-generator
sebastien-rosset Jun 1, 2020
3de8598
Merge branch 'master' of github.com:CiscoM31/openapi-generator into j…
sebastien-rosset Jun 1, 2020
e7cc55d
fix unit tests
sebastien-rosset Jun 1, 2020
163e738
continue implementation of discriminator lookup
sebastien-rosset Jun 1, 2020
797f518
throw deserialization exception when value is null and schema does no…
sebastien-rosset Jun 1, 2020
3752652
continue implementation of compose schema
sebastien-rosset Jun 2, 2020
e00545e
continue implementation of compose schema
sebastien-rosset Jun 2, 2020
700e0f9
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset Jun 2, 2020
8fa6f2b
Merge branch 'master' of github.com:CiscoM31/openapi-generator into j…
sebastien-rosset Jun 2, 2020
4753db4
continue implementation of compose schema
sebastien-rosset Jun 2, 2020
410a19d
Add more unit tests
sebastien-rosset Jun 2, 2020
45c10e1
Add unit tests for anyOf
sebastien-rosset Jun 2, 2020
589bfb8
Add unit tests
sebastien-rosset Jun 2, 2020
cf45a86
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset Jun 2, 2020
f3b8c05
Merge branch 'master' of github.com:CiscoM31/openapi-generator into j…
sebastien-rosset Jun 2, 2020
c66892e
Set supportsAdditionalPropertiesWithComposedSchema to true for Java j…
sebastien-rosset Jun 2, 2020
effd1d3
Support additional properties as nested field
sebastien-rosset Jun 2, 2020
71b8497
Support additional properties as nested field
sebastien-rosset Jun 3, 2020
0b6291c
add code comments
sebastien-rosset Jun 3, 2020
cf845f5
add customer deserializer
sebastien-rosset Jun 3, 2020
ad3fa7e
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset Jun 4, 2020
fa6cea1
Fix 'method too big' error with generated code
sebastien-rosset Jun 4, 2020
aa79612
resolve merge conflicts
sebastien-rosset Jun 4, 2020
7e469f6
resolve merge conflicts
sebastien-rosset Jun 4, 2020
12ecf34
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset Jun 4, 2020
d48a29a
Merge branch 'jersey2-method-too-big' of github.com:CiscoM31/openapi-…
sebastien-rosset Jun 4, 2020
6321dfc
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset Jun 4, 2020
ae8e870
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset Jun 5, 2020
d1f351b
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset Jun 5, 2020
7e2868b
Merge branch 'master' of github.com:CiscoM31/openapi-generator into j…
sebastien-rosset Jun 5, 2020
2bab4c6
Merge branch 'jersey2-improvement' of https://github.com/OpenAPITools…
sebastien-rosset Jun 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,14 @@ public void testOneOfSchemaWithDiscriminator() throws Exception {
assertNotNull(o);
assertTrue(o.getActualInstance() instanceof Zebra);
Zebra z = (Zebra)o.getActualInstance();
// TODO: this is incorrect: assert the value is Zebra.TypeEnum.PLAINS
assertNull(z.getType());
//assertEquals(Zebra.TypeEnum.PLAINS, z.getType());
assertEquals(Zebra.TypeEnum.PLAINS, z.getType());
}
{
// The discriminator value is valid but the 'type' value is invalid.
// TODO: the current deserialization code is incorrectly accepting the input data.
// The unit test code below should be rewritten to assert an exception.
String str = "{ \"className\": \"zebra\", \"type\": \"garbage_value\" }";
AbstractOpenApiSchema o = json.getContext(null).readValue(str, Mammal.class);
assertNotNull(o);
assertTrue(o.getActualInstance() instanceof Zebra);
Zebra z = (Zebra)o.getActualInstance();
assertNull(z.getType());
//Exception exception = assertThrows(JsonMappingException.class, () -> {
//json.getContext(null).readValue(str, Mammal.class);
//});
Exception exception = assertThrows(JsonMappingException.class, () -> {
json.getContext(null).readValue(str, Mammal.class);
});
}
{
// The discriminator value is zebra but the properties belong to Whale.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1647,10 +1647,24 @@ public void setAdditionalModelTypeAnnotations(final List<String> additionalModel

@Override
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
super.addAdditionPropertiesToCodeGenModel(codegenModel, schema);
if (!supportsAdditionalPropertiesWithComposedSchema) {
// The additional (undeclared) propertiees are modeled in Java as a HashMap.
//
// 1. supportsAdditionalPropertiesWithComposedSchema is set to false:
// The generated model class extends from the HashMap. That does not work
// with composed schemas that also use a discriminator because the model class
// is supposed to extend from the generated parent model class.
// 2. supportsAdditionalPropertiesWithComposedSchema is set to true:
// The HashMap is a field.
super.addAdditionPropertiesToCodeGenModel(codegenModel, schema);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 , this code avoids having the generated class extends from HashMap<String, T>. Instead, a additionalProperties field is added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastien-rosset I may have a better way for this. Let's have a chat via Slack today.

}

// See https://github.com/OpenAPITools/openapi-generator/pull/1729#issuecomment-449937728
codegenModel.additionalPropertiesType = getSchemaType(getAdditionalProperties(schema));
addImport(codegenModel, codegenModel.additionalPropertiesType);
Schema s = getAdditionalProperties(schema);
// 's' may be null if 'additionalProperties: false' in the OpenAPI schema.
if (s != null) {
codegenModel.additionalPropertiesType = getSchemaType(s);
addImport(codegenModel, codegenModel.additionalPropertiesType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public JavaClientCodegen() {
// inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values,
// and the discriminator mapping schemas in the OAS document.
this.setLegacyDiscriminatorBehavior(false);

}

@Override
Expand Down Expand Up @@ -371,6 +372,14 @@ public void processOpts() {
}
supportingFiles.add(new SupportingFile("AbstractOpenApiSchema.mustache", (sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar), "AbstractOpenApiSchema.java"));
forceSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON);

// Composed schemas can have the 'additionalProperties' keyword, as specified in JSON schema.
// In principle, this should be enabled by default for all code generators. However due to limitations
// in other code generators, support needs to be enabled on a case-by-case basis.
// The flag below should be set for all Java libraries, but the templates need to be ported
// one by one for each library.
supportsAdditionalPropertiesWithComposedSchema = true;

} else if (NATIVE.equals(getLibrary())) {
setJava8Mode(true);
additionalProperties.put("java8", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,7 @@ public abstract class AbstractOpenApiSchema {
return Boolean.FALSE;
}
}

{{>libraries/jersey2/additional_properties}}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,13 @@ public class JSON implements ContextResolver<ObjectMapper> {
Map<String, Class> discriminatorMappings;

// Constructs a new class discriminator.
ClassDiscriminatorMapping(Class cls, String name) {
ClassDiscriminatorMapping(Class cls, String propertyName, Map<String, Class> mappings) {
modelClass = cls;
discriminatorName = name;
discriminatorName = propertyName;
discriminatorMappings = new HashMap<String, Class>();
}

// Register a discriminator mapping for the specified model class.
void registerMapping(String mapping, Class cls) {
discriminatorMappings.put(mapping, cls);
if (mappings != null) {
discriminatorMappings.putAll(mappings);
}
}

// Return the name of the discriminator property for this model class.
Expand Down Expand Up @@ -215,41 +213,35 @@ public class JSON implements ContextResolver<ObjectMapper> {
return false;
}

/**
* A map of discriminators for all model classes.
*/
private static Map<Class, ClassDiscriminatorMapping> modelDiscriminators = new HashMap<Class, ClassDiscriminatorMapping>();

/**
* Register the discriminators for all composed models.
* A map of oneOf/anyOf descendants for each model class.
*/
private static void registerDiscriminators() {
{{#models}}
{{#model}}
{{#discriminator}}
{
// Initialize the discriminator mappings for '{{classname}}'.
ClassDiscriminatorMapping m = new ClassDiscriminatorMapping({{classname}}.class, "{{propertyBaseName}}");
{{#mappedModels}}
m.registerMapping("{{mappingName}}", {{modelName}}.class);
{{/mappedModels}}
m.registerMapping("{{name}}", {{classname}}.class);
modelDiscriminators.put({{classname}}.class, m);
}
{{/discriminator}}
{{/model}}
{{/models}}
}

private static Map<Class, Map<String, GenericType>> modelDescendants = new HashMap<Class, Map<String, GenericType>>();

/**
* Register the oneOf/anyOf descendants.
* TODO: this should not be a public method.
*/
public static void registerDescendants(Class modelClass, Map<String, GenericType> descendants) {
modelDescendants.put(modelClass, descendants);
* Register a model class discriminator.
*
* @param modelClass the model class
* @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) {
ClassDiscriminatorMapping m = new ClassDiscriminatorMapping(modelClass, discriminatorPropertyName, mappings);
modelDiscriminators.put(modelClass, m);
}

static {
registerDiscriminators();
/**
* Register the oneOf/anyOf descendants of the modelClass.
*
* @param modelClass the model class
* @param descendants a map of oneOf/anyOf descendants.
*/
public static void registerDescendants(Class modelClass, Map<String, GenericType> descendants) {
modelDescendants.put(modelClass, descendants);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{#additionalPropertiesType}}
/**
* A container for additional, undeclared properties.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 , this is the code that has the additionalProperties field

* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*/
@JsonUnwrapped
private Map<String, {{{.}}}> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
* If the property does not already exist, create it otherwise replace it.
*/
public {{classname}} putAdditionalProperty(String key, {{{.}}} value) {
if (this.additionalProperties == null) {
this.additionalProperties = new HashMap<String, {{{.}}}>();
}
this.additionalProperties.put(key, value);
return this;
}

/**
* Return the additional (undeclared) property with the specified name.
*/
public {{{.}}} getAdditionalProperty(String key) {
if (this.additionalProperties == null) {
return null;
}
return this.additionalProperties.get(key);
}
{{/additionalPropertiesType}}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import {{invokerPackage}}.JSON;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -65,6 +62,28 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
throw new IOException(String.format("Failed deserialization for {{classname}}: no match found"));
}

{{#additionalPropertiesType}}
/**
* Method called to deal with a property that did not map to a known Bean property.
* Method can deal with the problem as it sees fit (ignore, throw exception); but if it does return,
* it has to skip the matching Json content parser has.
*
* @param p - Parser that points to value of the unknown property
* @param ctxt - Context for deserialization; allows access to the parser, error reporting functionality
* @param instanceOrClass - Instance that is being populated by this deserializer, or if not known, Class that would be instantiated. If null, will assume type is what getValueClass() returns.
* @param propName - Name of the property that cannot be mapped
*/
@Override
protected void handleUnknownProperty(JsonParser p,
DeserializationContext ctxt,
Object instanceOrClass,
String propName) throws IOException {
System.out.println("Deserializing unknown property " + propName);
{{{.}}} deserialized = p.readValueAs({{{.}}}.class);
additionalProperties.put(propName, deserialized);
}
{{/additionalPropertiesType}}

/**
* Handle deserialization of the 'null' value.
*/
Expand All @@ -85,7 +104,18 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
public {{classname}}() {
super("anyOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
}
{{> libraries/jersey2/additional_properties }}
{{#additionalPropertiesType}}
@Override
public boolean equals(Object o) {
return super.equals(o) && Objects.equals(this.additionalProperties, o.additionalProperties)
}

@Override
public int hashCode() {
return Objects.hash(instance, isNullable, schemaType, additionalProperties);
}
{{/additionalPropertiesType}}
{{#anyOf}}
public {{classname}}({{{.}}} o) {
super("anyOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
Expand All @@ -99,6 +129,15 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
});
{{/anyOf}}
JSON.registerDescendants({{classname}}.class, Collections.unmodifiableMap(schemas));
{{#discriminator}}
// Initialize and register the discriminator mappings.
Map<String, Class> mappings = new HashMap<String, Class>();
{{#mappedModels}}
mappings.put("{{mappingName}}", {{modelName}}.class);
{{/mappedModels}}
mappings.put("{{name}}", {{classname}}.class);
JSON.registerDiscriminator({{classname}}.class, "{{propertyBaseName}}", mappings);
{{/discriminator}}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ package {{package}};
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
{{/useReflectionEqualsHashCode}}
{{#models}}
{{#model}}
{{#additionalPropertiesType}}
import java.util.Map;
import java.util.HashMap;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
{{/additionalPropertiesType}}
{{/model}}
{{/models}}
{{^supportJava6}}
import java.util.Objects;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
{{/supportJava6}}
{{#supportJava6}}
import org.apache.commons.lang3.ObjectUtils;
Expand Down Expand Up @@ -39,6 +50,7 @@ import javax.validation.Valid;
{{#performBeanValidation}}
import org.hibernate.validator.constraints.*;
{{/performBeanValidation}}
import {{invokerPackage}}.JSON;

{{#models}}
{{#model}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import {{invokerPackage}}.JSON;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -73,6 +70,28 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
throw new IOException(String.format("Failed deserialization for {{classname}}: %d classes match result, expected 1", match));
}

{{#additionalPropertiesType}}
/**
* Method called to deal with a property that did not map to a known Bean property.
* Method can deal with the problem as it sees fit (ignore, throw exception); but if it does return,
* it has to skip the matching Json content parser has.
*
* @param p - Parser that points to value of the unknown property
* @param ctxt - Context for deserialization; allows access to the parser, error reporting functionality
* @param instanceOrClass - Instance that is being populated by this deserializer, or if not known, Class that would be instantiated. If null, will assume type is what getValueClass() returns.
* @param propName - Name of the property that cannot be mapped
*/
@Override
protected void handleUnknownProperty(JsonParser p,
DeserializationContext ctxt,
Object instanceOrClass,
String propName) throws IOException {
System.out.println("Deserializing unknown property " + propName);
{{{.}}} deserialized = p.readValueAs({{{.}}}.class);
additionalProperties.put(propName, deserialized);
}
{{/additionalPropertiesType}}

/**
* Handle deserialization of the 'null' value.
*/
Expand All @@ -93,7 +112,18 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
public {{classname}}() {
super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
}
{{> libraries/jersey2/additional_properties }}
{{#additionalPropertiesType}}
@Override
public boolean equals(Object o) {
return super.equals(o) && Objects.equals(this.additionalProperties, o.additionalProperties)
}

@Override
public int hashCode() {
return Objects.hash(instance, isNullable, schemaType, additionalProperties);
}
{{/additionalPropertiesType}}
{{#oneOf}}
public {{classname}}({{{.}}} o) {
super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
Expand All @@ -107,6 +137,15 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
});
{{/oneOf}}
JSON.registerDescendants({{classname}}.class, Collections.unmodifiableMap(schemas));
{{#discriminator}}
// Initialize and register the discriminator mappings.
Map<String, Class> mappings = new HashMap<String, Class>();
{{#mappedModels}}
mappings.put("{{mappingName}}", {{modelName}}.class);
{{/mappedModels}}
mappings.put("{{name}}", {{classname}}.class);
JSON.registerDiscriminator({{classname}}.class, "{{propertyBaseName}}", mappings);
{{/discriminator}}
}

@Override
Expand Down
Loading