OpenAPITools / OpenAPITools/openapi-generator
[BUG][Go] Restricting output to models results in source code that can't be compiled
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
With global properties, it's possible to reduce the generation of files that are not needed for a particular application.
The Go generator was recently extended to support nullable types, and now includes a number of utility functions and types for this purpose.
Unfortunately, these utilities are suppressed when restricting the openapi-generator output to models. It's necessary to enable supportingFiles output to produce them.
On the other hand, when enabling supportingFiles, a lot of other files are generated (.travis.yml, .gitignore, git_push.sh, etc.), which need to be excluded individually when they're not needed. This is cumbersome and not future-proof.
openapi-generator version
7.0.0
OpenAPI declaration file content or url
openapi: 3.0.0
info:
description: Test API
version: 1.0.0
title: Test
servers:
- url: https://api.example.com
components:
schemas:
MyType:
type: object
description: Some type
properties:
field:
type: string
description: Some field
example: abc
paths: {}
Generation Details
docker run --rm -v "$(pwd):/local" openapitools/openapi-generator-cli:v7.0.0 generate -i /local/openapi.yaml -g go -o /local --global-property models,modelDocs=false
Steps to reproduce
- Generate
model_my_type.gousing the command line above - Try to use the model in other source code
- This fails, because the model uses the type
MappedNullable, which is defined inutils.go, and this file is not produced by the "models" template
Related issues/PRs
N/A
Suggest a fix
The "models" file set should include everything needed to compile the model source code.
Alternatively, there should be a flag to disable extra "supportingFiles" that have nothing to do with the source code itself.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Go generator's handling of the global-property models output and the generated model_my_type.go and utils.go files. Reproduce the Docker command from the issue, then verify that restricting output to models produces compilable model source without requiring unrelated supporting files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100