Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Golang code - issue with Unset() method for Nullable object #11693

Open
5 of 6 tasks
wguo-github opened this issue Feb 23, 2022 · 0 comments
Open
5 of 6 tasks

[BUG] Golang code - issue with Unset() method for Nullable object #11693

wguo-github opened this issue Feb 23, 2022 · 0 comments

Comments

@wguo-github
Copy link

wguo-github commented Feb 23, 2022

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

As of version 5.4.0, Golang generated code appears to not compile correctly when using the --generate-alias-as-model option. Specifically, when referencing a schema within an array, the generated code now no longer uses pointer variables, which causes a compile error in the Unset() method.

Suppose the following schema snippet:

components:
  schemas:
    webhook:
      type: object
      properties:
        somefield:
          type: string
    webhook.list:
      description: List of webhooks.
      type: array
      items:
        $ref: '#/components/schemas/webhook'

This generates the following Go code (relevant parts shown):

// WebhookList List of webhooks.
type WebhookList struct {
	Items []Webhook
}

type NullableWebhookList struct {
	value WebhookList
	isSet bool
}

func (v *NullableWebhookList) Unset() {
	v.value = nil // This line causes a compilation error as assigning nil to a struct
	v.isSet = false
}

Previously the value variable was a pointer i.e. value *WebhookList as opposed to value WebhookList), so the nil assignment in Unset() worked. However this behaviour has changed in 5.4.0.

openapi-generator version

5.4.0
Appears to be a regression, this was working fine in 5.3.0

OpenAPI declaration file content or url
---
openapi: 3.0.1
info:
  title: Test
  version: 20200511-01

paths:
  /test:
    post:
      tags:
        - Test
      summary: Test
      requestBody:
        description: Test
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/webhook.list'
        required: true
      responses:
        200:
          description: The request has been accepted.
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string

components:
  schemas:
    webhook:
      type: object
      properties:
        somefield:
          type: string
    webhook.list:
      description: List of webhooks.
      type: array
      items:
        $ref: '#/components/schemas/webhook'
Generation Details

Option --generate-alias-as-model is used to generate the above Go code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant