Skip to content

Commit

Permalink
Support $ref alongside description in OpenAPI V3 (google#314)
Browse files Browse the repository at this point in the history
* Support  with description in OpenAPI V3 proto
* Fix proto generation
  • Loading branch information
Jefftree authored Mar 14, 2022
1 parent a03001a commit 418d86c
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 300 deletions.
33 changes: 33 additions & 0 deletions openapiv3/OpenAPIv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -3433,6 +3433,24 @@ func NewReference(in *yaml.Node, context *compiler.Context) (*Reference, error)
errors = append(errors, compiler.NewError(context, message))
}
}
// string summary = 2;
v2 := compiler.MapValueForKey(m, "summary")
if v2 != nil {
x.Summary, ok = compiler.StringForScalarNode(v2)
if !ok {
message := fmt.Sprintf("has unexpected value for summary: %s", compiler.Display(v2))
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 3;
v3 := compiler.MapValueForKey(m, "description")
if v3 != nil {
x.Description, ok = compiler.StringForScalarNode(v3)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %s", compiler.Display(v3))
errors = append(errors, compiler.NewError(context, message))
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
Expand Down Expand Up @@ -6189,6 +6207,13 @@ func (m *Reference) ResolveReferences(root string) (*yaml.Node, error) {
if err != nil {
return nil, err
}
if info != nil {
replacement, err := NewReference(info, nil)
if err == nil {
*m = *replacement
return m.ResolveReferences(root)
}
}
return info, nil
}
return nil, compiler.NewErrorGroupOrNil(errors)
Expand Down Expand Up @@ -7979,6 +8004,14 @@ func (m *Reference) ToRawInfo() *yaml.Node {
// always include this required field.
info.Content = append(info.Content, compiler.NewScalarNodeForString("$ref"))
info.Content = append(info.Content, compiler.NewScalarNodeForString(m.XRef))
if m.Summary != "" {
info.Content = append(info.Content, compiler.NewScalarNodeForString("summary"))
info.Content = append(info.Content, compiler.NewScalarNodeForString(m.Summary))
}
if m.Description != "" {
info.Content = append(info.Content, compiler.NewScalarNodeForString("description"))
info.Content = append(info.Content, compiler.NewScalarNodeForString(m.Description))
}
return info
}

Expand Down
Loading

0 comments on commit 418d86c

Please sign in to comment.