[Go] whitelist AdditionalProperties in the field name (#6543)

* whitelist AdditionalProperties in Go field name

* code format
This commit is contained in:
William Cheng
2020-06-04 21:55:10 +08:00
committed by GitHub
parent ae790ea74e
commit 2be0afffe2

View File

@@ -29,7 +29,6 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.*;
import static org.openapitools.codegen.utils.OnceLogger.once;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;
@@ -94,7 +93,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
"byte",
"map[string]interface{}",
"interface{}"
)
)
);
instantiationTypes.clear();
@@ -210,6 +209,11 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
if (name.matches("^\\d.*"))
name = "Var" + name;
if ("AdditionalProperties".equals(name)) {
// AdditionalProperties is a reserved field (additionalProperties: true), use AdditionalPropertiesField instead
return "AdditionalPropertiesField";
}
return name;
}
@@ -320,7 +324,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
/**
* Return the golang implementation type for the specified property.
*
*
* @param p the OAS property.
* @return the golang implementation type.
*/
@@ -378,7 +382,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
/**
* Return the OpenAPI type for the property.
*
*
* @param p the OAS property.
* @return the OpenAPI type.
*/
@@ -404,20 +408,19 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
/**
* Determines the golang instantiation type of the specified schema.
*
* <p>
* This function is called when the input schema is a map, and specifically
* when the 'additionalProperties' attribute is present in the OAS specification.
* Codegen invokes this function to resolve the "parent" association to
* 'additionalProperties'.
*
* <p>
* Note the 'parent' attribute in the codegen model is used in the following scenarios:
* - Indicate a polymorphic association with some other type (e.g. class inheritance).
* - If the specification has a discriminator, cogegen create a “parent” based on the discriminator.
* - Use of the 'additionalProperties' attribute in the OAS specification.
* This is the specific scenario when codegen invokes this function.
* This is the specific scenario when codegen invokes this function.
*
* @param property the input schema
*
* @return the golang instantiation type of the specified property.
*/
@Override