Added missing extensions to contact and license

Not sure how I missed these, however, better late than never.
This commit is contained in:
quobix
2024-09-09 12:41:44 -04:00
parent 3e0da6d0b7
commit 0200809765
3 changed files with 30 additions and 16 deletions

View File

@@ -4,8 +4,9 @@
package base package base
import ( import (
low2 "github.com/pb33f/libopenapi/datamodel/high" "github.com/pb33f/libopenapi/datamodel/high"
low "github.com/pb33f/libopenapi/datamodel/low/base" low "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/orderedmap"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
@@ -17,6 +18,7 @@ type Contact struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty"` URL string `json:"url,omitempty" yaml:"url,omitempty"`
Email string `json:"email,omitempty" yaml:"email,omitempty"` Email string `json:"email,omitempty" yaml:"email,omitempty"`
Extensions *orderedmap.Map[string, *yaml.Node] `json:"-" yaml:"-"`
low *low.Contact `json:"-" yaml:"-"` // low-level representation low *low.Contact `json:"-" yaml:"-"` // low-level representation
} }
@@ -27,6 +29,7 @@ func NewContact(contact *low.Contact) *Contact {
c.URL = contact.URL.Value c.URL = contact.URL.Value
c.Name = contact.Name.Value c.Name = contact.Name.Value
c.Email = contact.Email.Value c.Email = contact.Email.Value
c.Extensions = high.ExtractExtensions(contact.Extensions)
return c return c
} }
@@ -45,6 +48,6 @@ func (c *Contact) Render() ([]byte, error) {
} }
func (c *Contact) MarshalYAML() (interface{}, error) { func (c *Contact) MarshalYAML() (interface{}, error) {
nb := low2.NewNodeBuilder(c, c.low) nb := high.NewNodeBuilder(c, c.low)
return nb.Render(), nil return nb.Render(), nil
} }

View File

@@ -4,8 +4,9 @@
package base package base
import ( import (
low2 "github.com/pb33f/libopenapi/datamodel/high" "github.com/pb33f/libopenapi/datamodel/high"
low "github.com/pb33f/libopenapi/datamodel/low/base" low "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/orderedmap"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
@@ -17,6 +18,7 @@ type License struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty"` URL string `json:"url,omitempty" yaml:"url,omitempty"`
Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"` Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"`
Extensions *orderedmap.Map[string, *yaml.Node] `json:"-" yaml:"-"`
low *low.License low *low.License
} }
@@ -24,6 +26,7 @@ type License struct {
func NewLicense(license *low.License) *License { func NewLicense(license *low.License) *License {
l := new(License) l := new(License)
l.low = license l.low = license
l.Extensions = high.ExtractExtensions(license.Extensions)
if !license.URL.IsEmpty() { if !license.URL.IsEmpty() {
l.URL = license.URL.Value l.URL = license.URL.Value
} }
@@ -53,6 +56,6 @@ func (l *License) Render() ([]byte, error) {
// MarshalYAML will create a ready to render YAML representation of the License object. // MarshalYAML will create a ready to render YAML representation of the License object.
func (l *License) MarshalYAML() (interface{}, error) { func (l *License) MarshalYAML() (interface{}, error) {
nb := low2.NewNodeBuilder(l, l.low) nb := high.NewNodeBuilder(l, l.low)
return nb.Render(), nil return nb.Render(), nil
} }

View File

@@ -8,6 +8,7 @@ import (
"crypto/sha256" "crypto/sha256"
"github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/index" "github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/orderedmap"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"strings" "strings"
) )
@@ -20,6 +21,7 @@ type Contact struct {
Name low.NodeReference[string] Name low.NodeReference[string]
URL low.NodeReference[string] URL low.NodeReference[string]
Email low.NodeReference[string] Email low.NodeReference[string]
Extensions *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]
KeyNode *yaml.Node KeyNode *yaml.Node
RootNode *yaml.Node RootNode *yaml.Node
*low.Reference *low.Reference
@@ -31,6 +33,7 @@ func (c *Contact) Build(ctx context.Context, keyNode, root *yaml.Node, _ *index.
c.RootNode = root c.RootNode = root
c.Reference = new(low.Reference) c.Reference = new(low.Reference)
c.Nodes = low.ExtractNodes(ctx, root) c.Nodes = low.ExtractNodes(ctx, root)
c.Extensions = low.ExtractExtensions(root)
return nil return nil
} }
@@ -58,3 +61,8 @@ func (c *Contact) Hash() [32]byte {
} }
return sha256.Sum256([]byte(strings.Join(f, "|"))) return sha256.Sum256([]byte(strings.Join(f, "|")))
} }
// GetExtensions returns all extensions for Contact
func (c *Contact) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]] {
return c.Extensions
}