-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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] [Go] object nullable not working #2119
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
Hi @hatappi ,
|
Btw, I don't think OAS 3.0.6 has released yet. The latest is "3.0.2": https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md |
@ackintosh @wing328 test.yaml openapi: "3.0.2"
info:
version: "1.0"
title: test
paths:
/test:
get:
summary: test
responses:
'200':
description: OK
components:
schemas:
user:
type: object
properties:
name:
type: string
nullable: true
age:
type: integer
nullable: true
address:
type: object
nullable: true
properties:
city:
type: string command docker run --rm \
-v ${PWD}:/local \
openapitools/openapi-generator-cli \
generate \
-i /local/test.yaml \
-g go \
-o /local/pkg generated model /*
* test
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 1.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package openapi
type User struct {
Name *string `json:"name,omitempty"`
Age *int32 `json:"age,omitempty"`
Address UserAddress `json:"address,omitempty"`
} |
Thank you very much for reporting issue! |
Hmm.. @wing328 @ackintosh |
Thanks @kemokemo . Let me check 👀 |
Ah 💡 It is due to InlineModelResolver. (The issue doesn't caused by the Go generator. All generator faces the issue) Line 888 in f76dca8
|
I'll file a PR to fix the missing |
@hatappi The fix has been merged into master but the docker image |
@ackintosh |
The docker image has been updated. I've verified with the image that the type User struct {
Name *string `json:"name,omitempty"`
Age *int32 `json:"age,omitempty"`
- Address UserAddress `json:"address,omitempty"`
+ Address *UserAddress `json:"address,omitempty"`
} Again thanks for reporting this issue. 👍 |
@ackintosh |
Description
output json using Go
struct
.When there is no value in strcut, it may not be displayed in json.
In such a case I will use pointer.
However, if specify
nullable: true
for the object in the definition file, it will not be output with a pointer.For integer and string pointers are given.
openapi-generator version
OpenAPI declaration file content or url
test.yaml
model.mustache
Command line used for generation
docker run --rm \ -v ${PWD}:/local \ openapitools/openapi-generator-cli:v3.3.4 \ generate \ -i /local/test.yaml \ -g go \ -o /local/pkg \ -t /local/templates
Steps to reproduce
templates/model.mustache
The text was updated successfully, but these errors were encountered: