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

openapi3: handle tangible *nil in Schema.IsEmpty impl #858

Merged
merged 3 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 1 addition & 13 deletions openapi3/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,19 +974,7 @@ func (loader *Loader) resolvePathItemRef(doc *T, pathItem *PathItem, documentPat
return
}
if ref := pathItem.Ref; ref != "" {
if pathItem.Summary != "" ||
pathItem.Description != "" ||
pathItem.Connect != nil ||
pathItem.Delete != nil ||
pathItem.Get != nil ||
pathItem.Head != nil ||
pathItem.Options != nil ||
pathItem.Patch != nil ||
pathItem.Post != nil ||
pathItem.Put != nil ||
pathItem.Trace != nil ||
len(pathItem.Servers) != 0 ||
len(pathItem.Parameters) != 0 {
if !pathItem.isEmpty() {
return
}
if isSingleRefElement(ref) {
Expand Down
19 changes: 19 additions & 0 deletions openapi3/path_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,22 @@ func (pathItem *PathItem) Validate(ctx context.Context, opts ...ValidationOption

return validateExtensions(ctx, pathItem.Extensions)
}

// isEmpty's introduced in 546590b1
func (pathItem *PathItem) isEmpty() bool {
// NOTE: ignores pathItem.Extensions
// NOTE: ignores pathItem.Ref
return pathItem.Summary == "" &&
pathItem.Description == "" &&
pathItem.Connect == nil &&
pathItem.Delete == nil &&
pathItem.Get == nil &&
pathItem.Head == nil &&
pathItem.Options == nil &&
pathItem.Patch == nil &&
pathItem.Post == nil &&
pathItem.Put == nil &&
pathItem.Trace == nil &&
len(pathItem.Servers) == 0 &&
len(pathItem.Parameters) == 0
}
14 changes: 7 additions & 7 deletions openapi3/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,35 +790,35 @@ func (schema *Schema) IsEmpty() bool {
schema.MinProps != 0 || schema.MaxProps != nil {
return false
}
if n := schema.Not; n != nil && !n.Value.IsEmpty() {
if n := schema.Not; n != nil && n.Value != nil && !n.Value.IsEmpty() {
return false
}
if ap := schema.AdditionalProperties.Schema; ap != nil && !ap.Value.IsEmpty() {
if ap := schema.AdditionalProperties.Schema; ap != nil && ap.Value != nil && !ap.Value.IsEmpty() {
return false
}
if apa := schema.AdditionalProperties.Has; apa != nil && !*apa {
return false
}
if items := schema.Items; items != nil && !items.Value.IsEmpty() {
if items := schema.Items; items != nil && items.Value != nil && !items.Value.IsEmpty() {
return false
}
for _, s := range schema.Properties {
if !s.Value.IsEmpty() {
if ss := s.Value; ss != nil && !ss.IsEmpty() {
return false
}
}
for _, s := range schema.OneOf {
if !s.Value.IsEmpty() {
if ss := s.Value; ss != nil && !ss.IsEmpty() {
return false
}
}
for _, s := range schema.AnyOf {
if !s.Value.IsEmpty() {
if ss := s.Value; ss != nil && !ss.IsEmpty() {
return false
}
}
for _, s := range schema.AllOf {
if !s.Value.IsEmpty() {
if ss := s.Value; ss != nil && !ss.IsEmpty() {
return false
}
}
Expand Down