Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7961
Closed
Open
Issue created Nov 17, 2020 by Administrator@rootContributor4 of 6 checklist items completed4/6 checklist items

[BUG][Go] UnmarshalJson has unused variable err if spec has oneOf without discriminator

Created by: code-lucidal58

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

In the openAPI spec, if a schema has oneOf but does not have a discriminator and the config useOneOfDiscriminatorLookup is set to True, the unmarshalJson function is incorrectly generated. Such a scenario can arise when the schema looks as follows:

Pet:
  description: a pet
  oneOf:
  - type: 'null'
  - $ref: "#/components/schemas/dog"
  - $ref: "#/components/schemas/cat"

Considering the fact that there are other schemas in this spec that may have oneOf without type: 'null', the configuration useOneOfDiscriminatorLookup: True is required. As a result, the unmarshal function for the above object is as follows:

func (dst *Pet) UnmarshalJSON(data []byte) error {
	var err error
	// this object is nullable so check if the payload is null or empty string
	if string(data) == "" || string(data) == "{}" {
		return nil
	}
	return nil
}

Building this generates an error because the variable err is declared but not used.

openapi-generator version

Master build with last commit id 023e6dd9

Suggest a fix

Allow unmarshalling of data even if nodiscriminator is mentioned whenuseOneOfDiscriminatorLookup: True

Assignee
Assign to
Time tracking