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

[Go] whitelist AdditionalProperties in the field name #6543

Merged
merged 2 commits into from
Jun 4, 2020
Merged
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 @@ -29,7 +29,6 @@
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;

Expand Down Expand Up @@ -94,7 +93,7 @@ public AbstractGoCodegen() {
"byte",
"map[string]interface{}",
"interface{}"
)
)
);

instantiationTypes.clear();
Expand Down Expand Up @@ -210,6 +209,11 @@ public String toVarName(String name) {
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;
}

Expand Down Expand Up @@ -320,7 +324,7 @@ public String toApiFilename(String name) {

/**
* Return the golang implementation type for the specified property.
*
*
* @param p the OAS property.
* @return the golang implementation type.
*/
Expand Down Expand Up @@ -378,7 +382,7 @@ public String getTypeDeclaration(Schema p) {

/**
* Return the OpenAPI type for the property.
*
*
* @param p the OAS property.
* @return the OpenAPI type.
*/
Expand All @@ -404,20 +408,19 @@ public String getSchemaType(Schema p) {

/**
* 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
Expand Down