diff --git a/datamodel/high/base/contact.go b/datamodel/high/base/contact.go index a33ce90..068b812 100644 --- a/datamodel/high/base/contact.go +++ b/datamodel/high/base/contact.go @@ -4,8 +4,9 @@ package base import ( - low2 "github.com/pb33f/libopenapi/datamodel/high" + "github.com/pb33f/libopenapi/datamodel/high" low "github.com/pb33f/libopenapi/datamodel/low/base" + "github.com/pb33f/libopenapi/orderedmap" "gopkg.in/yaml.v3" ) @@ -14,10 +15,11 @@ import ( // v2 - https://swagger.io/specification/v2/#contactObject // v3 - https://spec.openapis.org/oas/v3.1.0#contact-object type Contact struct { - Name string `json:"name,omitempty" yaml:"name,omitempty"` - URL string `json:"url,omitempty" yaml:"url,omitempty"` - Email string `json:"email,omitempty" yaml:"email,omitempty"` - low *low.Contact `json:"-" yaml:"-"` // low-level representation + Name string `json:"name,omitempty" yaml:"name,omitempty"` + URL string `json:"url,omitempty" yaml:"url,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 } // NewContact will create a new Contact instance using a low-level Contact @@ -27,6 +29,7 @@ func NewContact(contact *low.Contact) *Contact { c.URL = contact.URL.Value c.Name = contact.Name.Value c.Email = contact.Email.Value + c.Extensions = high.ExtractExtensions(contact.Extensions) return c } @@ -45,6 +48,6 @@ func (c *Contact) Render() ([]byte, error) { } func (c *Contact) MarshalYAML() (interface{}, error) { - nb := low2.NewNodeBuilder(c, c.low) + nb := high.NewNodeBuilder(c, c.low) return nb.Render(), nil } diff --git a/datamodel/high/base/license.go b/datamodel/high/base/license.go index 3c6d506..967eed5 100644 --- a/datamodel/high/base/license.go +++ b/datamodel/high/base/license.go @@ -4,8 +4,9 @@ package base import ( - low2 "github.com/pb33f/libopenapi/datamodel/high" + "github.com/pb33f/libopenapi/datamodel/high" low "github.com/pb33f/libopenapi/datamodel/low/base" + "github.com/pb33f/libopenapi/orderedmap" "gopkg.in/yaml.v3" ) @@ -14,9 +15,10 @@ import ( // v2 - https://swagger.io/specification/v2/#licenseObject // v3 - https://spec.openapis.org/oas/v3.1.0#license-object type License struct { - Name string `json:"name,omitempty" yaml:"name,omitempty"` - URL string `json:"url,omitempty" yaml:"url,omitempty"` - Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` + URL string `json:"url,omitempty" yaml:"url,omitempty"` + Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"` + Extensions *orderedmap.Map[string, *yaml.Node] `json:"-" yaml:"-"` low *low.License } @@ -24,6 +26,7 @@ type License struct { func NewLicense(license *low.License) *License { l := new(License) l.low = license + l.Extensions = high.ExtractExtensions(license.Extensions) if !license.URL.IsEmpty() { 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. func (l *License) MarshalYAML() (interface{}, error) { - nb := low2.NewNodeBuilder(l, l.low) + nb := high.NewNodeBuilder(l, l.low) return nb.Render(), nil } diff --git a/datamodel/low/base/contact.go b/datamodel/low/base/contact.go index 2f044db..1935849 100644 --- a/datamodel/low/base/contact.go +++ b/datamodel/low/base/contact.go @@ -8,6 +8,7 @@ import ( "crypto/sha256" "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/index" + "github.com/pb33f/libopenapi/orderedmap" "gopkg.in/yaml.v3" "strings" ) @@ -17,11 +18,12 @@ import ( // v2 - https://swagger.io/specification/v2/#contactObject // v3 - https://spec.openapis.org/oas/v3.1.0#contact-object type Contact struct { - Name low.NodeReference[string] - URL low.NodeReference[string] - Email low.NodeReference[string] - KeyNode *yaml.Node - RootNode *yaml.Node + Name low.NodeReference[string] + URL low.NodeReference[string] + Email low.NodeReference[string] + Extensions *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]] + KeyNode *yaml.Node + RootNode *yaml.Node *low.Reference low.NodeMap } @@ -31,6 +33,7 @@ func (c *Contact) Build(ctx context.Context, keyNode, root *yaml.Node, _ *index. c.RootNode = root c.Reference = new(low.Reference) c.Nodes = low.ExtractNodes(ctx, root) + c.Extensions = low.ExtractExtensions(root) return nil } @@ -58,3 +61,8 @@ func (c *Contact) Hash() [32]byte { } 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 +}