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

Proposal: x-omitempty for general types #1623

Closed
zhuangqh opened this issue Jul 18, 2018 · 1 comment
Closed

Proposal: x-omitempty for general types #1623

zhuangqh opened this issue Jul 18, 2018 · 1 comment
Labels
enhancement model Related to swagger generate model command

Comments

@zhuangqh
Copy link
Contributor

Problem statement

Currently, we use x-omitempty to exclude null array value. related PR #1189
Maybe x-omitempty can support general type to control the omityempty tag.

Foo:
  type: "object"
  properties:
    hasOmitEmptyTrue:
      type: string
      x-omitempty: true
    hasOmitEmptyFalse:
      type: string
      x-omitempty: false

produce

type Foo struct {
	// has omit empty false
	HasOmitEmptyFalse string `json:"hasOmitEmptyFalse"`
	// has omit empty true
	HasOmitEmptyTrue string `json:"hasOmitEmptyTrue,omitempty"`
}

Swagger specification

Steps to reproduce

Environment

swagger version: x.x.x
go version: x.x.x
OS:

@fredbi
Copy link
Contributor

fredbi commented Nov 20, 2018

Closed with #1751

@fredbi fredbi closed this as completed Nov 20, 2018
fredbi added a commit to fredbi/go-swagger that referenced this issue Dec 26, 2019
* fixes go-swagger#2116
* tests are embedded with existing testcase for go-swagger#1623 (added by go-swagger#1751)
* ensure arrays are not omitempty-ed by default, including arrays declared as properties

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Dec 26, 2019
* fixes go-swagger#2116
* tests are embedded with existing testcase for go-swagger#1623 (added by go-swagger#1751)
* ensure arrays are not omitempty-ed by default, including arrays declared as properties

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 10, 2020
* fixes go-swagger#2116
* tests are embedded with existing testcase for go-swagger#1623 (added by go-swagger#1751)
* ensure arrays are not omitempty-ed by default, including arrays declared as properties

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 10, 2020
* fixes go-swagger#2116
* tests are embedded with existing testcase for go-swagger#1623 (added by go-swagger#1751)
* ensure arrays are not omitempty-ed by default, including arrays declared as properties

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 26, 2020
* fixes go-swagger#2116
* tests are embedded with existing testcase for go-swagger#1623 (added by go-swagger#1751)
* ensure arrays are not omitempty-ed by default, including arrays declared as properties

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 26, 2020
* fixes go-swagger#2116
* tests are embedded with existing testcase for go-swagger#1623 (added by go-swagger#1751)
* ensure arrays are not omitempty-ed by default, including arrays declared as properties

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit that referenced this issue Jan 26, 2020
* Fixed x-omitempty in the case of $ref'ed schemas

* fixes #2116
* tests are embedded with existing testcase for #1623 (added by #1751)
* ensure arrays are not omitempty-ed by default, including arrays declared as properties

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>

* * reverted on breaking change

In order to avoid introducing breaking changes, adopted the following rule regarding default setting for omitempty on arrays:
- arrays of primitives are by default not empty-omitted
- arrays used as aliased types (e.g. in properties), remain empty-omitted by default

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement model Related to swagger generate model command
Projects
None yet
Development

No branches or pull requests

2 participants