mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
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:
@@ -6,9 +6,9 @@ package base
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
|
||||||
"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"
|
||||||
"github.com/pb33f/libopenapi/utils"
|
"github.com/pb33f/libopenapi/utils"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -22,6 +22,7 @@ type License struct {
|
|||||||
Name low.NodeReference[string]
|
Name low.NodeReference[string]
|
||||||
URL low.NodeReference[string]
|
URL low.NodeReference[string]
|
||||||
Identifier low.NodeReference[string]
|
Identifier 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
|
||||||
@@ -36,10 +37,8 @@ func (l *License) Build(ctx context.Context, keyNode, root *yaml.Node, idx *inde
|
|||||||
utils.CheckForMergeNodes(root)
|
utils.CheckForMergeNodes(root)
|
||||||
l.Reference = new(low.Reference)
|
l.Reference = new(low.Reference)
|
||||||
no := low.ExtractNodes(ctx, root)
|
no := low.ExtractNodes(ctx, root)
|
||||||
|
l.Extensions = low.ExtractExtensions(root)
|
||||||
l.Nodes = no
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,3 +66,8 @@ func (l *License) Hash() [32]byte {
|
|||||||
}
|
}
|
||||||
return sha256.Sum256([]byte(strings.Join(f, "|")))
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
package base
|
package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"github.com/pb33f/libopenapi/datamodel/low"
|
"github.com/pb33f/libopenapi/datamodel/low"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@@ -62,24 +61,3 @@ description: the ranch`
|
|||||||
assert.Equal(t, lDoc.Hash(), rDoc.Hash())
|
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())
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user