From 7bdbfed467cce96f5e268dfe76ebcc9e8b0ae062 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 28 Aug 2021 22:43:53 +0800 Subject: [PATCH] Remove skipReadonlyPropertiesInInit option (#10269) * remove skipReadonlyPropertiesInInit option * fix removal * more removal * fix again --- bin/configs/go-petstore.yaml | 1 - docs/generators/go.md | 1 - .../codegen/CodegenConstants.java | 3 --- .../codegen/languages/GoClientCodegen.java | 16 ------------ .../main/resources/go/model_simple.mustache | 25 ------------------- 5 files changed, 46 deletions(-) diff --git a/bin/configs/go-petstore.yaml b/bin/configs/go-petstore.yaml index 5e4970c6cd47..6d78e55f1c98 100644 --- a/bin/configs/go-petstore.yaml +++ b/bin/configs/go-petstore.yaml @@ -7,4 +7,3 @@ additionalProperties: packageName: petstore disallowAdditionalPropertiesIfNotPresent: false generateInterfaces: true - skipReadonlyPropertiesInInt: false \ No newline at end of file diff --git a/docs/generators/go.md b/docs/generators/go.md index fc380778cc30..a2318c003f30 100644 --- a/docs/generators/go.md +++ b/docs/generators/go.md @@ -15,7 +15,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl |packageName|Go package name (convention: lowercase).| |openapi| |packageVersion|Go package version.| |1.0.0| |prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| -|skipReadonlyPropertiesInInit|Skip default values to the readOnly properties in the model init function| |true| |structPrefix|whether to prefix struct with the class name. e.g. DeletePetOpts => PetApiDeletePetOpts| |false| |useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped.| |false| |withAWSV4Signature|whether to include AWS v4 signature support| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java index c32f62cb43a5..bb7aa069fe7a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java @@ -388,7 +388,4 @@ public class CodegenConstants { "If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default."; public static final String USE_ONEOF_DISCRIMINATOR_LOOKUP = "useOneOfDiscriminatorLookup"; public static final String USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC = "Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped."; - - public static final String SKIP_READONLY_PROPERTIES_IN_INIT = "skipReadonlyPropertiesInInit"; - public static final String SKIP_READONLY_PROPERTIES_IN_INIT_DESC = "Skip default values to the readOnly properties in the model init function"; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java index 78a5efb91f6a..60c0d9117db8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java @@ -48,7 +48,6 @@ public class GoClientCodegen extends AbstractGoCodegen { protected String goImportAlias = "openapiclient"; protected boolean isGoSubmodule = false; protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup - protected boolean skipReadonlyPropertiesInInt = false; // A cache to efficiently lookup schema `toModelName()` based on the schema Key private Map schemaKeyToModelNameCache = new HashMap<>(); @@ -113,7 +112,6 @@ public class GoClientCodegen extends AbstractGoCodegen { .defaultValue(Boolean.FALSE.toString())); cliOptions.add(new CliOption(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC).defaultValue("false")); - cliOptions.add(new CliOption(CodegenConstants.SKIP_READONLY_PROPERTIES_IN_INIT, CodegenConstants.SKIP_READONLY_PROPERTIES_IN_INIT_DESC).defaultValue("true")); // option to change how we process + set the data in the 'additionalProperties' keyword. CliOption disallowAdditionalPropertiesIfNotPresentOpt = CliOption.newBoolean( CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT, @@ -242,12 +240,6 @@ public class GoClientCodegen extends AbstractGoCodegen { additionalProperties.put(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, getUseOneOfDiscriminatorLookup()); } - if (additionalProperties.containsKey(CodegenConstants.SKIP_READONLY_PROPERTIES_IN_INIT)) { - setSkipReadonlyPropertiesInInit(convertPropertyToBooleanAndWriteBack(CodegenConstants.SKIP_READONLY_PROPERTIES_IN_INIT)); - } else { - additionalProperties.put(CodegenConstants.SKIP_READONLY_PROPERTIES_IN_INIT, getSkipReadonlyPropertiesInInit()); - } - if (additionalProperties.containsKey(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT)) { this.setDisallowAdditionalPropertiesIfNotPresent(Boolean.parseBoolean(additionalProperties .get(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT).toString())); @@ -274,14 +266,6 @@ public class GoClientCodegen extends AbstractGoCodegen { return this.useOneOfDiscriminatorLookup; } - public void setSkipReadonlyPropertiesInInit(boolean skipReadonlyPropertiesInInt) { - this.skipReadonlyPropertiesInInt = skipReadonlyPropertiesInInt; - } - - public boolean getSkipReadonlyPropertiesInInit() { - return this.skipReadonlyPropertiesInInt; - } - public void setGoImportAlias(String goImportAlias) { this.goImportAlias = goImportAlias; } diff --git a/modules/openapi-generator/src/main/resources/go/model_simple.mustache b/modules/openapi-generator/src/main/resources/go/model_simple.mustache index 339b6e627aed..97884f910b33 100644 --- a/modules/openapi-generator/src/main/resources/go/model_simple.mustache +++ b/modules/openapi-generator/src/main/resources/go/model_simple.mustache @@ -43,17 +43,6 @@ func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} {{dataType}}{{^-last} {{^required}} {{#defaultValue}} {{^vendorExtensions.x-golang-is-container}} -{{#skipReadonlyPropertiesInInt}} -{{#isNullable}} - var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}} - this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}}) -{{/isNullable}} -{{^isNullable}} - var {{nameInCamelCase}} {{{dataType}}} = {{{.}}} - this.{{name}} = &{{nameInCamelCase}} -{{/isNullable}} -{{/skipReadonlyPropertiesInInt}} -{{^skipReadonlyPropertiesInInt}} {{^isReadOnly}} {{#isNullable}} var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}} @@ -64,7 +53,6 @@ func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} {{dataType}}{{^-last} this.{{name}} = &{{nameInCamelCase}} {{/isNullable}} {{/isReadOnly}} -{{/skipReadonlyPropertiesInInt}} {{/vendorExtensions.x-golang-is-container}} {{/defaultValue}} {{/required}} @@ -80,18 +68,6 @@ func New{{classname}}WithDefaults() *{{classname}} { {{#vars}} {{#defaultValue}} {{^vendorExtensions.x-golang-is-container}} -{{#skipReadonlyPropertiesInInt}} -{{#isNullable}} -{{!we use datatypeWithEnum here, since it will represent the non-nullable name of the datatype, e.g. int64 for NullableInt64}} - var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}} - this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}}) -{{/isNullable}} -{{^isNullable}} - var {{nameInCamelCase}} {{{dataType}}} = {{{.}}} - this.{{name}} = {{^required}}&{{/required}}{{nameInCamelCase}} -{{/isNullable}} -{{/skipReadonlyPropertiesInInt}} -{{^skipReadonlyPropertiesInInt}} {{^isReadOnly}} {{#isNullable}} {{!we use datatypeWithEnum here, since it will represent the non-nullable name of the datatype, e.g. int64 for NullableInt64}} @@ -103,7 +79,6 @@ func New{{classname}}WithDefaults() *{{classname}} { this.{{name}} = {{^required}}&{{/required}}{{nameInCamelCase}} {{/isNullable}} {{/isReadOnly}} -{{/skipReadonlyPropertiesInInt}} {{/vendorExtensions.x-golang-is-container}} {{/defaultValue}} {{/vars}}