forked from loafle/openapi-generator-original
Add isAdditionalPropertiesTrue (#6880)
* move postProcessModel to the end * add isAdditionalPropertiesTrue * remove supportsAdditionalPropertiesWithComposedSchema from go exp * remove x-additional-properties * update comment
This commit is contained in:
@@ -129,6 +129,11 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
*/
|
||||
public String additionalPropertiesType;
|
||||
|
||||
/**
|
||||
* True if additionalProperties is set to true (boolean value)
|
||||
*/
|
||||
public boolean isAdditionalPropertiesTrue;
|
||||
|
||||
private Integer maxProperties;
|
||||
private Integer minProperties;
|
||||
private boolean uniqueItems;
|
||||
|
||||
@@ -2483,19 +2483,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// remove duplicated properties
|
||||
m.removeAllDuplicatedProperty();
|
||||
|
||||
// post process model properties
|
||||
if (m.vars != null) {
|
||||
for (CodegenProperty prop : m.vars) {
|
||||
postProcessModelProperty(m, prop);
|
||||
}
|
||||
m.hasVars = m.vars.size() > 0;
|
||||
}
|
||||
if (m.allVars != null) {
|
||||
for (CodegenProperty prop : m.allVars) {
|
||||
postProcessModelProperty(m, prop);
|
||||
}
|
||||
}
|
||||
|
||||
// set isDiscriminator on the discriminator property
|
||||
if (m.discriminator != null) {
|
||||
String discPropName = m.discriminator.getPropertyBaseName();
|
||||
@@ -2525,6 +2512,32 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
Collections.sort(m.allVars, comparator);
|
||||
}
|
||||
|
||||
// process 'additionalProperties'
|
||||
if (schema.getAdditionalProperties() == null) {
|
||||
m.isAdditionalPropertiesTrue = false; // TODO fix the old (incorrect) behaviour (likely with an option)
|
||||
} else if (schema.getAdditionalProperties() instanceof Boolean) {
|
||||
if (Boolean.TRUE.equals(schema.getAdditionalProperties())) {
|
||||
m.isAdditionalPropertiesTrue = true;
|
||||
} else {
|
||||
m.isAdditionalPropertiesTrue = false;
|
||||
}
|
||||
} else {
|
||||
m.isAdditionalPropertiesTrue = false;
|
||||
}
|
||||
|
||||
// post process model properties
|
||||
if (m.vars != null) {
|
||||
for (CodegenProperty prop : m.vars) {
|
||||
postProcessModelProperty(m, prop);
|
||||
}
|
||||
m.hasVars = m.vars.size() > 0;
|
||||
}
|
||||
if (m.allVars != null) {
|
||||
for (CodegenProperty prop : m.allVars) {
|
||||
postProcessModelProperty(m, prop);
|
||||
}
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
@@ -222,11 +222,6 @@ public class GoClientExperimentalCodegen extends GoClientCodegen {
|
||||
if (model.anyOf != null && !model.anyOf.isEmpty()) {
|
||||
imports.add(createMapping("import", "fmt"));
|
||||
}
|
||||
|
||||
// add x-additional-properties
|
||||
if ("map[string]map[string]interface{}".equals(model.parent)) {
|
||||
model.vendorExtensions.put("x-additional-properties", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
|
||||
@@ -13,15 +13,15 @@ type {{classname}} struct {
|
||||
{{/description}}
|
||||
{{name}} {{^required}}{{^isNullable}}*{{/isNullable}}{{/required}}{{{dataType}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}`
|
||||
{{/vars}}
|
||||
{{#vendorExtensions.x-additional-properties}}
|
||||
{{#isAdditionalPropertiesTrue}}
|
||||
AdditionalProperties map[string]interface{}
|
||||
{{/vendorExtensions.x-additional-properties}}
|
||||
{{/isAdditionalPropertiesTrue}}
|
||||
}
|
||||
|
||||
{{#vendorExtensions.x-additional-properties}}
|
||||
{{#isAdditionalPropertiesTrue}}
|
||||
type _{{{classname}}} {{{classname}}}
|
||||
|
||||
{{/vendorExtensions.x-additional-properties}}
|
||||
{{/isAdditionalPropertiesTrue}}
|
||||
// New{{classname}} instantiates a new {{classname}} object
|
||||
// This constructor will assign default values to properties that have it defined,
|
||||
// and makes sure properties required by API are set, but the set of arguments
|
||||
@@ -253,17 +253,17 @@ func (o {{classname}}) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
{{/isNullable}}
|
||||
{{/vars}}
|
||||
{{#vendorExtensions.x-additional-properties}}
|
||||
{{#isAdditionalPropertiesTrue}}
|
||||
|
||||
for key, value := range o.AdditionalProperties {
|
||||
toSerialize[key] = value
|
||||
}
|
||||
|
||||
{{/vendorExtensions.x-additional-properties}}
|
||||
{{/isAdditionalPropertiesTrue}}
|
||||
return json.Marshal(toSerialize)
|
||||
}
|
||||
|
||||
{{#vendorExtensions.x-additional-properties}}
|
||||
{{#isAdditionalPropertiesTrue}}
|
||||
func (o *{{{classname}}}) UnmarshalJSON(bytes []byte) (err error) {
|
||||
var{{{classname}}} := _{{{classname}}}{}
|
||||
|
||||
@@ -283,5 +283,5 @@ func (o *{{{classname}}}) UnmarshalJSON(bytes []byte) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
{{/vendorExtensions.x-additional-properties}}
|
||||
{{/isAdditionalPropertiesTrue}}
|
||||
{{>nullable_model}}
|
||||
|
||||
@@ -16,11 +16,8 @@ import (
|
||||
// AdditionalPropertiesAnyType struct for AdditionalPropertiesAnyType
|
||||
type AdditionalPropertiesAnyType struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
AdditionalProperties map[string]interface{}
|
||||
}
|
||||
|
||||
type _AdditionalPropertiesAnyType AdditionalPropertiesAnyType
|
||||
|
||||
// NewAdditionalPropertiesAnyType instantiates a new AdditionalPropertiesAnyType object
|
||||
// This constructor will assign default values to properties that have it defined,
|
||||
// and makes sure properties required by API are set, but the set of arguments
|
||||
@@ -75,31 +72,9 @@ func (o AdditionalPropertiesAnyType) MarshalJSON() ([]byte, error) {
|
||||
if o.Name != nil {
|
||||
toSerialize["name"] = o.Name
|
||||
}
|
||||
|
||||
for key, value := range o.AdditionalProperties {
|
||||
toSerialize[key] = value
|
||||
}
|
||||
|
||||
return json.Marshal(toSerialize)
|
||||
}
|
||||
|
||||
func (o *AdditionalPropertiesAnyType) UnmarshalJSON(bytes []byte) (err error) {
|
||||
varAdditionalPropertiesAnyType := _AdditionalPropertiesAnyType{}
|
||||
|
||||
if err = json.Unmarshal(bytes, &varAdditionalPropertiesAnyType); err == nil {
|
||||
*o = AdditionalPropertiesAnyType(varAdditionalPropertiesAnyType)
|
||||
}
|
||||
|
||||
additionalProperties := make(map[string]interface{})
|
||||
|
||||
if err = json.Unmarshal(bytes, &additionalProperties); err == nil {
|
||||
delete(additionalProperties, "name")
|
||||
o.AdditionalProperties = additionalProperties
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
type NullableAdditionalPropertiesAnyType struct {
|
||||
value *AdditionalPropertiesAnyType
|
||||
isSet bool
|
||||
|
||||
@@ -28,11 +28,8 @@ type NullableClass struct {
|
||||
ObjectNullableProp map[string]map[string]interface{} `json:"object_nullable_prop,omitempty"`
|
||||
ObjectAndItemsNullableProp map[string]map[string]interface{} `json:"object_and_items_nullable_prop,omitempty"`
|
||||
ObjectItemsNullable *map[string]map[string]interface{} `json:"object_items_nullable,omitempty"`
|
||||
AdditionalProperties map[string]interface{}
|
||||
}
|
||||
|
||||
type _NullableClass NullableClass
|
||||
|
||||
// NewNullableClass instantiates a new NullableClass object
|
||||
// This constructor will assign default values to properties that have it defined,
|
||||
// and makes sure properties required by API are set, but the set of arguments
|
||||
@@ -536,42 +533,9 @@ func (o NullableClass) MarshalJSON() ([]byte, error) {
|
||||
if o.ObjectItemsNullable != nil {
|
||||
toSerialize["object_items_nullable"] = o.ObjectItemsNullable
|
||||
}
|
||||
|
||||
for key, value := range o.AdditionalProperties {
|
||||
toSerialize[key] = value
|
||||
}
|
||||
|
||||
return json.Marshal(toSerialize)
|
||||
}
|
||||
|
||||
func (o *NullableClass) UnmarshalJSON(bytes []byte) (err error) {
|
||||
varNullableClass := _NullableClass{}
|
||||
|
||||
if err = json.Unmarshal(bytes, &varNullableClass); err == nil {
|
||||
*o = NullableClass(varNullableClass)
|
||||
}
|
||||
|
||||
additionalProperties := make(map[string]interface{})
|
||||
|
||||
if err = json.Unmarshal(bytes, &additionalProperties); err == nil {
|
||||
delete(additionalProperties, "integer_prop")
|
||||
delete(additionalProperties, "number_prop")
|
||||
delete(additionalProperties, "boolean_prop")
|
||||
delete(additionalProperties, "string_prop")
|
||||
delete(additionalProperties, "date_prop")
|
||||
delete(additionalProperties, "datetime_prop")
|
||||
delete(additionalProperties, "array_nullable_prop")
|
||||
delete(additionalProperties, "array_and_items_nullable_prop")
|
||||
delete(additionalProperties, "array_items_nullable")
|
||||
delete(additionalProperties, "object_nullable_prop")
|
||||
delete(additionalProperties, "object_and_items_nullable_prop")
|
||||
delete(additionalProperties, "object_items_nullable")
|
||||
o.AdditionalProperties = additionalProperties
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
type NullableNullableClass struct {
|
||||
value *NullableClass
|
||||
isSet bool
|
||||
|
||||
Reference in New Issue
Block a user