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

String references should be nullable #1710

Open
willgottschalk opened this issue Nov 28, 2023 · 1 comment
Open

String references should be nullable #1710

willgottschalk opened this issue Nov 28, 2023 · 1 comment

Comments

@willgottschalk
Copy link

Describe the bug
The following struct:

type Response struct {
    Field *string `json:"field"
}

generates:

"definitions": {
  "Response": {
    "type": "object",
    "properties": {
      "string": {
        "type": "string"
      }
    }
  }
}

To Reproduce
Steps to reproduce the behavior:

Full Code for the repro

package main

type Response struct {
	Field *string `json:"string"`
}

// @Success 200 {object} Response
func HandleStuff() {
}

Expected behavior
I expect to see either: "type": ["string, "null"] or "required": true field. A reference to a string (or anything) will create a null value when serializing to json

Your swag version
e.g. 1.16.2

Your go version
go version go1.21.1 darwin/arm64

Desktop (please complete the following information):

  • OS: mac
  • Browser: chrome
  • Version: 119

Additional context
Add any other context about the problem here.

@sdghchj
Copy link
Member

sdghchj commented Nov 28, 2023

type Response struct {
    Field *string `json:"field" extensions:"x-nullable"`
} 

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

No branches or pull requests

2 participants