Commit 71c07650 authored by mbohlool's avatar mbohlool

All omitempty fields should be optional

parent 238459b0
...@@ -57,9 +57,14 @@ func hasOpenAPITagValue(comments []string, value string) bool { ...@@ -57,9 +57,14 @@ func hasOpenAPITagValue(comments []string, value string) bool {
return false return false
} }
func hasOptionalTag(comments []string) bool { // hasOptionalTag returns true if the member has +optional in its comments or
tagValues := types.ExtractCommentTags("+", comments)[tagOptional] // omitempty in its json tags.
return tagValues != nil func hasOptionalTag(m *types.Member) bool {
hasOptionalCommentTag := types.ExtractCommentTags(
"+", m.CommentLines)[tagOptional] != nil
hasOptionalJsonTag := strings.Contains(
reflect.StructTag(m.Tags).Get("json"), "omitempty")
return hasOptionalCommentTag || hasOptionalJsonTag
} }
// NameSystems returns the name system used by the generators in this package. // NameSystems returns the name system used by the generators in this package.
...@@ -288,7 +293,7 @@ func (g openAPITypeWriter) generate(t *types.Type) error { ...@@ -288,7 +293,7 @@ func (g openAPITypeWriter) generate(t *types.Type) error {
if name == "" { if name == "" {
continue continue
} }
if !hasOptionalTag(m.CommentLines) { if !hasOptionalTag(&m) {
required = append(required, name) required = append(required, name)
} }
if err := g.generateProperty(&m); err != nil { if err := g.generateProperty(&m); err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment