From 3e0da6d0b71c1d51aba416d25b99e8b9a485c1d9 Mon Sep 17 00:00:00 2001 From: quobix Date: Mon, 9 Sep 2024 12:41:11 -0400 Subject: [PATCH] removed error checking for URL and identifier. This was stupid and I regret doing this. It causes tons of issues downstream. --- datamodel/low/base/license.go | 12 ++++++++---- datamodel/low/base/license_test.go | 22 ---------------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/datamodel/low/base/license.go b/datamodel/low/base/license.go index 0499c52..c291ab4 100644 --- a/datamodel/low/base/license.go +++ b/datamodel/low/base/license.go @@ -6,9 +6,9 @@ package base import ( "context" "crypto/sha256" - "fmt" "github.com/pb33f/libopenapi/datamodel/low" "github.com/pb33f/libopenapi/index" + "github.com/pb33f/libopenapi/orderedmap" "github.com/pb33f/libopenapi/utils" "gopkg.in/yaml.v3" "strings" @@ -22,6 +22,7 @@ type License struct { Name low.NodeReference[string] URL low.NodeReference[string] Identifier low.NodeReference[string] + Extensions *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]] KeyNode *yaml.Node RootNode *yaml.Node *low.Reference @@ -36,10 +37,8 @@ func (l *License) Build(ctx context.Context, keyNode, root *yaml.Node, idx *inde utils.CheckForMergeNodes(root) l.Reference = new(low.Reference) no := low.ExtractNodes(ctx, root) + l.Extensions = low.ExtractExtensions(root) l.Nodes = no - if l.URL.Value != "" && l.Identifier.Value != "" { - return fmt.Errorf("license cannot have both a URL and an identifier, they are mutually exclusive") - } return nil } @@ -67,3 +66,8 @@ func (l *License) Hash() [32]byte { } return sha256.Sum256([]byte(strings.Join(f, "|"))) } + +// GetExtensions returns all extensions for License +func (l *License) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]] { + return l.Extensions +} diff --git a/datamodel/low/base/license_test.go b/datamodel/low/base/license_test.go index b8a0cb8..32e88be 100644 --- a/datamodel/low/base/license_test.go +++ b/datamodel/low/base/license_test.go @@ -4,7 +4,6 @@ package base import ( - "context" "github.com/pb33f/libopenapi/datamodel/low" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" @@ -62,24 +61,3 @@ description: the ranch` assert.Equal(t, lDoc.Hash(), rDoc.Hash()) } - -func TestLicense_WithIdentifierAndURL_Error(t *testing.T) { - - left := `identifier: MIT -url: https://pb33f.io -description: the ranch` - - var lNode yaml.Node - _ = yaml.Unmarshal([]byte(left), &lNode) - - // create low level objects - var lDoc License - err := low.BuildModel(lNode.Content[0], &lDoc) - assert.NoError(t, err) - - err = lDoc.Build(context.Background(), nil, lNode.Content[0], nil) - - assert.Error(t, err) - assert.Equal(t, "license cannot have both a URL and an identifier, they are mutually exclusive", err.Error()) - -}