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
  • #13842
Closed
Open
Issue created Oct 27, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][GO] generation of nil check for struct

Created by: NickUfer

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 generates code like

if someStruct{} == nil {
// ...

Which is invalid as a struct can't be nil.

go build output of my generated client:

[...]
./model_export_request.go:107:3: cannot use nil as type Files in return argument
./model_read_single_items_blogs_200_response.go:41:24: cannot convert nil to type ItemsBlogs
./model_read_single_items_blogs_200_response.go:51:24: cannot convert nil to type ItemsBlogs
./model_read_single_items_blogs_200_response.go:52:3: cannot use nil as type ItemsBlogs in return argument
./model_read_single_items_blogs_200_response.go:59:24: cannot convert nil to type ItemsBlogs
./model_read_single_items_blogs_200_response.go:73:12: cannot convert nil to type ItemsBlogs
[...]

image

openapi-generator version

6.2.0

OpenAPI declaration file content or url

This spec is generated by https://github.com/directus/directus

https://gist.github.com/NickUfer/3c004a00df5ca1420b9949613ddaeb61

Generation Details

config file:

disallowAdditionalPropertiesIfNotPresent: true
packageName: directusclient
generateInterfaces: true
structPrefix: true
enumClassPrefix: true

cmd:

generate -i /tmp/oas.yaml -g go -o "/tmp/directusclient" -c /tmp/go.yml
Steps to reproduce
Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking