Skip to content

Commit

Permalink
Merge pull request #293 from swagger-api/issue-291
Browse files Browse the repository at this point in the history
fixed discriminator on templates.
  • Loading branch information
HugoMario authored Feb 2, 2019
2 parents 24f0c73 + 6c5c7da commit d37f35c
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class JSON {
classByDiscriminatorValue.put("{{classname}}".toUpperCase(), {{classname}}.class);
return getClassByDiscriminator(
classByDiscriminatorValue,
getDiscriminatorValue(readElement, "{{discriminator}}"));
getDiscriminatorValue(readElement, "{{discriminator.propertyName}}"));
}
})
{{/parent}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator.propertyName}}", visible = true )
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/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
@@ -1,5 +1,5 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator.propertyName}}", visible = true )
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/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
@@ -1,5 +1,5 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator.propertyName}}", visible = true )
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/handlebars/csharp/modelGeneric.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// </summary>
[DataContract]
{{#discriminator}}
[JsonConverter(typeof(JsonSubtypes), "{{discriminator}}")]{{#children}}
[JsonConverter(typeof(JsonSubtypes), "{{discriminator.propertyName}}")]{{#children}}
[JsonSubtypes.KnownSubType(typeof({{classname}}), "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}")]{{/children}}
{{/discriminator}}
{{#generatePropertyChanged}}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/handlebars/php/model_generic.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^parentSchema}}implements ModelInterface, ArrayAccess{{/parentSchema}}
{
const DISCRIMINATOR = {{#discriminator}}'{{discriminator}}'{{/discriminator}}{{^discriminator}}null{{/discriminator}};
const DISCRIMINATOR = {{#discriminator}}'{{discriminator.propertyName}}'{{/discriminator}}{{^discriminator}}null{{/discriminator}};

/**
* The original name of the model.
Expand Down Expand Up @@ -166,7 +166,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa
{{#discriminator}}

// Initialize discriminator property with the model name.
$discriminator = array_search('{{discriminator}}', self::$attributeMap);
$discriminator = array_search('{{discriminator.propertyName}}', self::$attributeMap);
$this->container[$discriminator] = static::$swaggerModelName;
{{/discriminator}}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/handlebars/python/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class {{classname}}({{#parent}}{{parent}}{{/parent}}{{^parent}}object{{/parent}}
{{/@first}}
self._{{name}} = None
{{/vars}}
self.discriminator = {{#discriminator}}'{{discriminator}}'{{/discriminator}}{{^discriminator}}None{{/discriminator}}
self.discriminator = {{#discriminator}}'{{discriminator.propertyName}}'{{/discriminator}}{{^discriminator}}None{{/discriminator}}
{{#vars}}{{#@first}}
{{/@first}}
{{#required}}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mustache/Java/JSON.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class JSON {
classByDiscriminatorValue.put("{{classname}}".toUpperCase(), {{classname}}.class);
return getClassByDiscriminator(
classByDiscriminatorValue,
getDiscriminatorValue(readElement, "{{discriminator}}"));
getDiscriminatorValue(readElement, "{{discriminator.propertyName}}"));
}
})
{{/parent}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class JSON {
classByDiscriminatorValue.put("{{classname}}".toUpperCase(), {{classname}}.class);
return getClassByDiscriminator(
classByDiscriminatorValue,
getDiscriminatorValue(readElement, "{{discriminator}}"));
getDiscriminatorValue(readElement, "{{discriminator.propertyName}}"));
}
})
{{/parent}}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/mustache/Java/pojo.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
{{/parent}}
{{#gson}}
{{#discriminator}}
this.{{discriminator}} = this.getClass().getSimpleName();
this.{{discriminator.propertyName}} = this.getClass().getSimpleName();
{{/discriminator}}
{{/gson}}
}
Expand All @@ -83,7 +83,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
{{#gson}}
{{#discriminator}}
public {{classname}}() {
this.{{discriminator}} = this.getClass().getSimpleName();
this.{{discriminator.propertyName}} = this.getClass().getSimpleName();
}
{{/discriminator}}
{{/gson}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator.propertyName}}", visible = true )
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/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
@@ -1,5 +1,5 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator.propertyName}}", visible = true )
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/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
@@ -1,5 +1,5 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator.propertyName}}", visible = true )
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/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
@@ -1,5 +1,5 @@
{{#jackson}}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true )
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator.propertyName}}", visible = true )
@JsonSubTypes({
{{#children}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mustache/csharp/modelGeneric.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// </summary>
[DataContract]
{{#discriminator}}
[JsonConverter(typeof(JsonSubtypes), "{{discriminator}}")]{{#children}}
[JsonConverter(typeof(JsonSubtypes), "{{discriminator.propertyName}}")]{{#children}}
[JsonSubtypes.KnownSubType(typeof({{classname}}), "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}")]{{/children}}
{{/discriminator}}
{{#generatePropertyChanged}}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/mustache/php/model_generic.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^parentSchema}}implements ModelInterface, ArrayAccess{{/parentSchema}}
{
const DISCRIMINATOR = {{#discriminator}}'{{discriminator}}'{{/discriminator}}{{^discriminator}}null{{/discriminator}};
const DISCRIMINATOR = {{#discriminator}}'{{discriminator.propertyName}}'{{/discriminator}}{{^discriminator}}null{{/discriminator}};

/**
* The original name of the model.
Expand Down Expand Up @@ -166,7 +166,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa
{{#discriminator}}

// Initialize discriminator property with the model name.
$discriminator = array_search('{{discriminator}}', self::$attributeMap);
$discriminator = array_search('{{discriminator.propertyName}}', self::$attributeMap);
$this->container[$discriminator] = static::$swaggerModelName;
{{/discriminator}}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mustache/python/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class {{classname}}({{#parent}}{{parent}}{{/parent}}{{^parent}}object{{/parent}}
{{/-first}}
self._{{name}} = None
{{/vars}}
self.discriminator = {{#discriminator}}'{{discriminator}}'{{/discriminator}}{{^discriminator}}None{{/discriminator}}
self.discriminator = {{#discriminator}}'{{discriminator.propertyName}}'{{/discriminator}}{{^discriminator}}None{{/discriminator}}
{{#vars}}{{#-first}}
{{/-first}}
{{#required}}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mustache/swift3/Models.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class Decoders {
if let sourceDictionary = source as? [AnyHashable: Any] {
{{#discriminator}}
// Check discriminator to support inheritance
if let discriminator = sourceDictionary["{{discriminator}}"] as? String, instance == nil && discriminator != "{{classname}}"{
if let discriminator = sourceDictionary["{{discriminator.propertyName}}"] as? String, instance == nil && discriminator != "{{classname}}"{
return Decoders.decode(clazz: {{classname}}.self, discriminator: discriminator, source: source)
}
{{/discriminator}}
Expand Down

0 comments on commit d37f35c

Please sign in to comment.