From 8b562cb8b8a0791ac62cd671c7c2c38391042efd Mon Sep 17 00:00:00 2001 From: Juan Hernandez Date: Thu, 18 May 2023 17:07:20 +0200 Subject: [PATCH] Honor `@json` annotation in OpenAPI generator Currently the OpenAPI specification generator doesn't honor the `@json` annotation. This patch fixes that. Signed-off-by: Juan Hernandez --- pkg/generators/openapi/names_calculator.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/generators/openapi/names_calculator.go b/pkg/generators/openapi/names_calculator.go index 2a09ceb..00ad681 100644 --- a/pkg/generators/openapi/names_calculator.go +++ b/pkg/generators/openapi/names_calculator.go @@ -20,6 +20,7 @@ import ( "fmt" "path/filepath" + "github.com/openshift-online/ocm-api-metamodel/pkg/annotations" "github.com/openshift-online/ocm-api-metamodel/pkg/concepts" "github.com/openshift-online/ocm-api-metamodel/pkg/reporter" ) @@ -80,7 +81,11 @@ func (c *NamesCalculator) SchemaName(typ *concepts.Type) string { // AttributePropertyName calculates the property name for an attribute of a struct type. func (c *NamesCalculator) AttributePropertyName(attribute *concepts.Attribute) string { - return attribute.Name().Snake() + name := annotations.JSONName(attribute) + if name == "" { + name = attribute.Name().Snake() + } + return name } // ParameterPropertyName calculates the property name for an parameter of a method.