Skip to content

Commit

Permalink
Merge pull request go-openapi#91 from sttts/sttts-nullable
Browse files Browse the repository at this point in the history
Add nullable
  • Loading branch information
casualjim authored May 10, 2019
2 parents 9d9763c + 915f417 commit b2056d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions items.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
// SimpleSchema describe swagger simple schemas for parameters and headers
type SimpleSchema struct {
Type string `json:"type,omitempty"`
Nullable bool `json:"nullable,omitempty"`
Format string `json:"format,omitempty"`
Items *Items `json:"items,omitempty"`
CollectionFormat string `json:"collectionFormat,omitempty"`
Expand Down Expand Up @@ -91,6 +92,12 @@ func (i *Items) Typed(tpe, format string) *Items {
return i
}

// AsNullable flags this schema as nullable.
func (i *Items) AsNullable() *Items {
i.Nullable = true
return i
}

// CollectionOf a fluent builder method for an array item
func (i *Items) CollectionOf(items *Items, format string) *Items {
i.Type = jsonArray
Expand Down
7 changes: 7 additions & 0 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ type SchemaProps struct {
Schema SchemaURL `json:"-"`
Description string `json:"description,omitempty"`
Type StringOrArray `json:"type,omitempty"`
Nullable bool `json:"nullable,omitempty"`
Format string `json:"format,omitempty"`
Title string `json:"title,omitempty"`
Default interface{} `json:"default,omitempty"`
Expand Down Expand Up @@ -302,6 +303,12 @@ func (s *Schema) AddType(tpe, format string) *Schema {
return s
}

// AsNullable flags this schema as nullable.
func (s *Schema) AsNullable() *Schema {
s.Nullable = true
return s
}

// CollectionOf a fluent builder method for an array parameter
func (s *Schema) CollectionOf(items Schema) *Schema {
s.Type = []string{jsonArray}
Expand Down

0 comments on commit b2056d6

Please sign in to comment.