Skip to content

[BUG][GO] AnyOf causes compilation error for Go #10430

Description

@deliveroo-andreik

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The generator produces broken code for anyOf

openapi-generator version

v5.2.1

OpenAPI declaration file content or url
Generation Details

generate
--global-property models
--global-property modelDocs=false
--additional-properties sourceFolder=dto,useOneOfDiscriminatorLookup=true
--model-package dto
--package-name dto
-i /local/docs/openapi.yaml
--generate-alias-as-model
-g go
-o /local/internal/server/rest

func (dst *WebhookEvent) UnmarshalJSON(data []byte) error {
	var err error
	// use discriminator value to speed up the lookup
	var jsonDict map[string]interface{}
	err := json.Unmarshal(data, &jsonDict) // <---- compilation error as err already declared in var
	if err != nil {
		return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.")
	}
}
Steps to reproduce
Related issues/PRs
Suggest a fix

fix the template and remove unnecessary colon

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions