removed error checking for URL and identifier.

This was stupid and I regret doing this. It causes tons of issues downstream.
This commit is contained in:
quobix
2024-09-09 12:41:11 -04:00
parent 69f408bd8e
commit 3e0da6d0b7
2 changed files with 8 additions and 26 deletions

View File

@@ -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
}

View File

@@ -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())
}