mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
Added missing extensions to contact and license
Not sure how I missed these, however, better late than never.
This commit is contained in:
@@ -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"
|
||||
)
|
||||
|
||||
@@ -17,6 +18,7 @@ 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"`
|
||||
Extensions *orderedmap.Map[string, *yaml.Node] `json:"-" yaml:"-"`
|
||||
low *low.Contact `json:"-" yaml:"-"` // low-level representation
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -17,6 +18,7 @@ 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"`
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -20,6 +21,7 @@ type Contact struct {
|
||||
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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user