From 80afd55e3b20191b7dda728e493f82ccc86fbad2 Mon Sep 17 00:00:00 2001 From: Vicente Pinto Date: Fri, 27 Sep 2024 15:33:57 +0100 Subject: [PATCH] Add omitempty tag for required and read-only/write-only fields --- scripts/download-oas.sh | 1 - templates/go/model_simple.mustache | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/download-oas.sh b/scripts/download-oas.sh index 21fafa2..e2c6f9e 100755 --- a/scripts/download-oas.sh +++ b/scripts/download-oas.sh @@ -56,7 +56,6 @@ for service_dir in ${work_dir}/${OAS_REPO_NAME}/services/*; do # To support initial integrations of the IaaS API in an Alpha state, we will temporarily use it to generate an IaaS Alpha SDK module # This check can be removed once the IaaS API moves all endpoints to Beta if [[ ${service} == "iaas" ]]; then - echo "found alpha iaas" mv -f ${dir}/*.json ${ROOT_DIR}/oas/iaasalpha.json fi if [[ ${ALLOW_ALPHA} != "true" ]]; then diff --git a/templates/go/model_simple.mustache b/templates/go/model_simple.mustache index b331bc0..a7b57b4 100644 --- a/templates/go/model_simple.mustache +++ b/templates/go/model_simple.mustache @@ -30,9 +30,13 @@ type {{classname}} struct { // Can be cast to float32 without loss of precision. {{/isFloat}} {{#required}} +{{^isReadOnly}} +{{^isWriteOnly}} // REQUIRED +{{/isWriteOnly}} +{{/isReadOnly}} {{/required}} - {{name}} *{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{{dataType}}}{{/isNumeric}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` + {{name}} *{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{{dataType}}}{{/isNumeric}} `json:"{{baseName}}{{#required}}{{#isReadOnly}},omitempty{{/isReadOnly}}{{/required}}{{#required}}{{#isWriteOnly}},omitempty{{/isWriteOnly}}{{/required}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` {{#isAdditionalPropertiesTrue}} AdditionalProperties map[string]interface{} {{/isAdditionalPropertiesTrue}}