Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java][client] oneof support for jackson clients #4785

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -10,6 +10,8 @@
public class CodegenDiscriminator {
private String propertyName;
private String propertyBaseName;
private String propertyGetter;
private String propertyType;
private Map<String, String> mapping;
private Set<MappedModel> mappedModels = new LinkedHashSet<>();

Expand All @@ -21,6 +23,14 @@ public void setPropertyName(String propertyName) {
this.propertyName = propertyName;
}

public String getPropertyGetter() {
return propertyGetter;
}

public void setPropertyGetter(String propertyGetter) {
this.propertyGetter = propertyGetter;
}

public String getPropertyBaseName() {
return propertyBaseName;
}
Expand All @@ -29,6 +39,14 @@ public void setPropertyBaseName(String propertyBaseName) {
this.propertyBaseName = propertyBaseName;
}

public String getPropertyType() {
return propertyType;
}

public void setPropertyType(String propertyType) {
this.propertyType = propertyType;
}

public Map<String, String> getMapping() {
return mapping;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,10 @@ public String toAnyOfName(List<String> names, ComposedSchema composedSchema) {
*/
@SuppressWarnings("static-method")
public String toOneOfName(List<String> names, ComposedSchema composedSchema) {
Map<String, Object> exts = composedSchema.getExtensions();
if (exts != null && exts.containsKey("x-oneOf-name")) {
return (String) exts.get("x-oneOf-name");
}
return "oneOf<" + String.join(",", names) + ">";
}

Expand Down Expand Up @@ -2117,13 +2121,16 @@ public int compare(CodegenProperty one, CodegenProperty another) {
return m;
}

private CodegenDiscriminator createDiscriminator(String schemaName, Schema schema) {
protected CodegenDiscriminator createDiscriminator(String schemaName, Schema schema) {
if (schema.getDiscriminator() == null) {
return null;
}
CodegenDiscriminator discriminator = new CodegenDiscriminator();
discriminator.setPropertyName(toVarName(schema.getDiscriminator().getPropertyName()));
discriminator.setPropertyBaseName(schema.getDiscriminator().getPropertyName());
discriminator.setPropertyGetter(toGetter(discriminator.getPropertyName()));
// FIXME: for now, we assume that the discriminator property is String
discriminator.setPropertyType(typeMapping.get("string"));
discriminator.setMapping(schema.getDiscriminator().getMapping());
if (schema.getDiscriminator().getMapping() != null && !schema.getDiscriminator().getMapping().isEmpty()) {
for (Entry<String, String> e : schema.getDiscriminator().getMapping().entrySet()) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ import org.hibernate.validator.constraints.*;

{{#models}}
{{#model}}
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>pojo}}{{/isEnum}}
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#vendorExtensions.isOneOfInterface}}{{>oneof_interface}}{{/vendorExtensions.isOneOfInterface}}{{^vendorExtensions.isOneOfInterface}}{{>pojo}}{{/vendorExtensions.isOneOfInterface}}{{/isEnum}}
{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.util.Map;
public class {{classname}}Test {
{{#models}}
{{#model}}
{{^vendorExtensions.isOneOfInterface}}
{{^isEnum}}
private final {{classname}} model = new {{classname}}();

Expand All @@ -43,6 +44,7 @@ public class {{classname}}Test {
}

{{/allVars}}
{{/vendorExtensions.isOneOfInterface}}
{{/model}}
{{/models}}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{>typeInfoAnnotation}}{{>xmlAnnotation}}
public interface {{classname}} {{#vendorExtensions.implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.implements}} {
{{#discriminator}}
public {{propertyType}} {{propertyGetter}}();
{{/discriminator}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
})
{{/jackson}}
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcelableModel}}implements Parcelable {{#serializableModel}}, Serializable {{/serializableModel}}{{/parcelableModel}}{{^parcelableModel}}{{#serializableModel}}implements Serializable {{/serializableModel}}{{/parcelableModel}}{
public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorExtensions.implements}}{{#-first}}implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{#-last}} {{/-last}}{{/vendorExtensions.implements}}{
{{#serializableModel}}
private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# {{classname}}
# {{#vendorExtensions.isOneOfInterface}}Interface {{/vendorExtensions.isOneOfInterface}}{{classname}}

{{#description}}{{&description}}
{{/description}}
{{^vendorExtensions.isOneOfInterface}}
## Properties

Name | Type | Description | Notes
Expand All @@ -17,3 +18,19 @@ Name | Value
---- | -----{{#allowableValues}}{{#enumVars}}
{{name}} | {{value}}{{/enumVars}}{{/allowableValues}}
{{/isEnum}}{{/vars}}
{{#vendorExtensions.implements.0}}

## Implemented Interfaces

{{#vendorExtensions.implements}}
* {{{.}}}
{{/vendorExtensions.implements}}
{{/vendorExtensions.implements.0}}
{{/vendorExtensions.isOneOfInterface}}
{{#vendorExtensions.isOneOfInterface}}
## Implementing Classes

{{#oneOf}}
* {{{.}}}
{{/oneOf}}
{{/vendorExtensions.isOneOfInterface}}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{#jackson}}

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminator.propertyBaseName}}}", visible = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "{{{discriminator.propertyBaseName}}}", visible = true)
@JsonSubTypes({
{{#discriminator.mappedModels}}
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
})
@javax.annotation.concurrent.Immutable

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Animal.JSON_PROPERTY_COLOR
})

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Animal.JSON_PROPERTY_COLOR
})

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Animal.JSON_PROPERTY_COLOR
})

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Animal.JSON_PROPERTY_COLOR
})

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Animal.JSON_PROPERTY_COLOR
})

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Animal.JSON_PROPERTY_COLOR
})

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Animal.JSON_PROPERTY_COLOR
})

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Name | Type | Description | Notes
**name** | **String** | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Name | Type | Description | Notes
**name** | **String** | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Name | Type | Description | Notes
**name** | **String** | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ Name | Type | Description | Notes
**anytype3** | [**Object**](.md) | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Name | Type | Description | Notes
**name** | **String** | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Name | Type | Description | Notes
**name** | **String** | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Name | Type | Description | Notes
**name** | **String** | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Name | Type | Description | Notes
**name** | **String** | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ Name | Type | Description | Notes
**color** | **String** | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Name | Type | Description | Notes
**arrayArrayNumber** | [**List&lt;List&lt;BigDecimal&gt;&gt;**](List.md) | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Name | Type | Description | Notes
**arrayNumber** | [**List&lt;BigDecimal&gt;**](BigDecimal.md) | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ Name | Type | Description | Notes
**arrayArrayOfModel** | [**List&lt;List&lt;ReadOnlyFirst&gt;&gt;**](List.md) | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ LEOPARDS | &quot;leopards&quot;
JAGUARS | &quot;jaguars&quot;


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ LEOPARDS | &quot;leopards&quot;
JAGUARS | &quot;jaguars&quot;


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ Name | Type | Description | Notes
**ATT_NAME** | **String** | Name of the pet | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Name | Type | Description | Notes
**declawed** | **Boolean** | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Name | Type | Description | Notes
**declawed** | **Boolean** | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ Name | Type | Description | Notes
**name** | **String** | |


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ Name | Type | Description | Notes
**propertyClass** | **String** | | [optional]


## Implemented Interfaces

* Parcelable


Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ Name | Type | Description | Notes
**client** | **String** | | [optional]


## Implemented Interfaces

* Parcelable


Loading