swagger-api / swagger-api/swagger-codegen
[GO] Invalid code generated when specifying the "Any Type"
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The specification says I am able to declare an "any" type which should match any possible type. E.g. values in a JSON object.
The resulting code references Object, which is undefined and won't compile.
Swagger-codegen version
3.0.26
Swagger declaration file content or url
openapi: 3.0.0
info:
title: Hello
version: 1.0.0
components:
schemas:
AnyValue: {}
MyObject:
type: object
properties:
myField:
$ref: '#/components/schemas/AnyValue'
paths: {}
Command line used for generation
swagger-codegen generate -i swagger.yaml -l go -o swagger
Steps to reproduce
- Run the CLI as stated above
- Attempt to use:
➜ go run .
# myproject
swagger/model_my_object.go:12:11: undefined: Object
Furthermore inspect the code for model_my_object.go:
/*
* Hello
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 1.0.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
type MyObject struct {
MyField *Object `json:"myField,omitempty"`
}
Related issues/PRs
Suggest a fix/enhancement
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
Run the stated swagger-codegen generate -i swagger.yaml -l go -o swagger command and inspect model_my_object.go, focusing on how the empty AnyValue schema becomes the MyField type. Trace that generated type through the Go generator entry point and its templates, then verify that the generated package compiles and accepts arbitrary JSON values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100