mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 04:20:11 +00:00
The more in-depth we use extensions, the more likely is is that we need custom extensions. New `UnpackExtensions` function in the high package makes this easy. Low level models have been updated to support feature fully and docs added in README and examples as well. Signed-off-by: Dave Shanley <dave@quobix.com>
84 lines
1.5 KiB
Go
84 lines
1.5 KiB
Go
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v3
|
|
|
|
import (
|
|
"github.com/pb33f/libopenapi/datamodel/low"
|
|
"github.com/pb33f/libopenapi/index"
|
|
"github.com/stretchr/testify/assert"
|
|
"gopkg.in/yaml.v3"
|
|
"testing"
|
|
)
|
|
|
|
func TestPathItem_Hash(t *testing.T) {
|
|
|
|
yml := `description: a path item
|
|
summary: it's another path item
|
|
servers:
|
|
- url: https://pb33f.io
|
|
parameters:
|
|
- in: head
|
|
get:
|
|
description: get me
|
|
post:
|
|
description: post me
|
|
put:
|
|
description: put me
|
|
patch:
|
|
description: patch me
|
|
delete:
|
|
description: delete me
|
|
head:
|
|
description: top
|
|
options:
|
|
description: choices
|
|
trace:
|
|
description: find me
|
|
x-byebye: boebert`
|
|
|
|
var idxNode yaml.Node
|
|
_ = yaml.Unmarshal([]byte(yml), &idxNode)
|
|
idx := index.NewSpecIndex(&idxNode)
|
|
|
|
var n PathItem
|
|
_ = low.BuildModel(idxNode.Content[0], &n)
|
|
_ = n.Build(idxNode.Content[0], idx)
|
|
|
|
yml2 := `get:
|
|
description: get me
|
|
post:
|
|
description: post me
|
|
servers:
|
|
- url: https://pb33f.io
|
|
parameters:
|
|
- in: head
|
|
put:
|
|
description: put me
|
|
patch:
|
|
description: patch me
|
|
delete:
|
|
description: delete me
|
|
head:
|
|
description: top
|
|
options:
|
|
description: choices
|
|
trace:
|
|
description: find me
|
|
x-byebye: boebert
|
|
description: a path item
|
|
summary: it's another path item`
|
|
|
|
var idxNode2 yaml.Node
|
|
_ = yaml.Unmarshal([]byte(yml2), &idxNode2)
|
|
idx2 := index.NewSpecIndex(&idxNode2)
|
|
|
|
var n2 PathItem
|
|
_ = low.BuildModel(idxNode2.Content[0], &n2)
|
|
_ = n2.Build(idxNode2.Content[0], idx2)
|
|
|
|
// hash
|
|
assert.Equal(t, n.Hash(), n2.Hash())
|
|
assert.Len(t, n.GetExtensions(), 1)
|
|
}
|