mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
Merge branch 'main' of https://github.com/pb33f/libopenapi into v0.13.0
Signed-off-by: quobix <dave@quobix.com> # Conflicts: # what-changed/model/info_test.go
This commit is contained in:
BIN
.github/sponsors/scalar-dark.png
vendored
Normal file
BIN
.github/sponsors/scalar-dark.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 302 KiB |
BIN
.github/sponsors/scalar-light.png
vendored
Normal file
BIN
.github/sponsors/scalar-light.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 312 KiB |
13
README.md
13
README.md
@@ -29,6 +29,17 @@ like our _very kind_ sponsors:
|
||||
|
||||
[Speakeasy](https://speakeasyapi.dev/?utm_source=libopenapi+repo&utm_medium=github+sponsorship)
|
||||
|
||||
<a href="https://scalar.com">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset=".github/sponsors/scalar-dark.png">
|
||||
<img alt="scalar'" src=".github/sponsors/scalar-light.png">
|
||||
</picture>
|
||||
</a>
|
||||
|
||||
[scalar](https://scalar.com)
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
`libopenapi` is pretty new, so our list of notable projects that depend on `libopenapi` is small (let me know if you'd like to add your project)
|
||||
@@ -39,7 +50,7 @@ like our _very kind_ sponsors:
|
||||
- [github.com/danielgtaylor/restish](https://github.com/danielgtaylor/restish) - "Restish is a CLI for interacting with REST-ish HTTP APIs"
|
||||
- [github.com/speakeasy-api/speakeasy](https://github.com/speakeasy-api/speakeasy) - "Speakeasy CLI makes validating OpenAPI docs and generating idiomatic SDKs easy!"
|
||||
- [github.com/apicat/apicat](https://github.com/apicat/apicat) - "AI-powered API development tool"
|
||||
- [github.com/mattermost/mattermost](https://github.com/mattermost/mattermost) = "Software development lifecycle platform"
|
||||
- [github.com/mattermost/mattermost](https://github.com/mattermost/mattermost) - "Software development lifecycle platform"
|
||||
- Your project here?
|
||||
---
|
||||
|
||||
|
||||
@@ -11,8 +11,9 @@ import (
|
||||
// InfoChanges represents the number of changes to an Info object. Part of an OpenAPI document
|
||||
type InfoChanges struct {
|
||||
*PropertyChanges
|
||||
ContactChanges *ContactChanges `json:"contact,omitempty" yaml:"contact,omitempty"`
|
||||
LicenseChanges *LicenseChanges `json:"license,omitempty" yaml:"license,omitempty"`
|
||||
ContactChanges *ContactChanges `json:"contact,omitempty" yaml:"contact,omitempty"`
|
||||
LicenseChanges *LicenseChanges `json:"license,omitempty" yaml:"license,omitempty"`
|
||||
ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"`
|
||||
}
|
||||
|
||||
// GetAllChanges returns a slice of all changes made between Info objects
|
||||
@@ -25,6 +26,9 @@ func (i *InfoChanges) GetAllChanges() []*Change {
|
||||
if i.LicenseChanges != nil {
|
||||
changes = append(changes, i.LicenseChanges.GetAllChanges()...)
|
||||
}
|
||||
if i.ExtensionChanges != nil {
|
||||
changes = append(changes, i.ExtensionChanges.GetAllChanges()...)
|
||||
}
|
||||
return changes
|
||||
}
|
||||
|
||||
@@ -37,6 +41,9 @@ func (i *InfoChanges) TotalChanges() int {
|
||||
if i.LicenseChanges != nil {
|
||||
t += i.LicenseChanges.TotalChanges()
|
||||
}
|
||||
if i.ExtensionChanges != nil {
|
||||
t += i.ExtensionChanges.TotalChanges()
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
@@ -139,6 +146,10 @@ func CompareInfo(l, r *base.Info) *InfoChanges {
|
||||
l.License.ValueNode, nil, false, r.License.Value, nil)
|
||||
}
|
||||
}
|
||||
|
||||
// check extensions.
|
||||
i.ExtensionChanges = CompareExtensions(l.Extensions, r.Extensions)
|
||||
|
||||
i.PropertyChanges = NewPropertyChanges(changes)
|
||||
if i.TotalChanges() <= 0 {
|
||||
return nil
|
||||
|
||||
@@ -5,12 +5,13 @@ package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
"github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
"github.com/pb33f/libopenapi/datamodel/low/v3"
|
||||
v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCompareInfo_DescriptionAdded(t *testing.T) {
|
||||
@@ -375,7 +376,8 @@ contact:
|
||||
name: buckaroo
|
||||
email: buckaroo@pb33f.io
|
||||
license:
|
||||
name: MIT`
|
||||
name: MIT
|
||||
x-extension: extension`
|
||||
|
||||
right := `title: a nice spec
|
||||
termsOfService: https://pb33f.io/terms
|
||||
@@ -384,7 +386,8 @@ contact:
|
||||
name: buckaroo
|
||||
email: buckaroo@pb33f.io
|
||||
license:
|
||||
name: MIT`
|
||||
name: MIT
|
||||
x-extension: extension`
|
||||
|
||||
var lNode, rNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(left), &lNode)
|
||||
@@ -402,3 +405,97 @@ license:
|
||||
extChanges := CompareInfo(&lDoc, &rDoc)
|
||||
assert.Nil(t, extChanges)
|
||||
}
|
||||
|
||||
func TestCompareInfo_ExtensionAdded(t *testing.T) {
|
||||
|
||||
left := `title: a nice spec
|
||||
version: '1.2.3'
|
||||
`
|
||||
|
||||
right := `title: a nice spec
|
||||
version: '1.2.3'
|
||||
x-extension: new extension
|
||||
`
|
||||
|
||||
var lNode, rNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(left), &lNode)
|
||||
_ = yaml.Unmarshal([]byte(right), &rNode)
|
||||
|
||||
// create low level objects
|
||||
var lDoc base.Info
|
||||
var rDoc base.Info
|
||||
_ = low.BuildModel(lNode.Content[0], &lDoc)
|
||||
_ = low.BuildModel(rNode.Content[0], &rDoc)
|
||||
_ = lDoc.Build(nil, lNode.Content[0], nil)
|
||||
_ = rDoc.Build(nil, rNode.Content[0], nil)
|
||||
|
||||
// compare.
|
||||
extChanges := CompareInfo(&lDoc, &rDoc)
|
||||
assert.Equal(t, 1, extChanges.TotalChanges())
|
||||
assert.Len(t, extChanges.GetAllChanges(), 1)
|
||||
assert.Equal(t, ObjectAdded, extChanges.ExtensionChanges.Changes[0].ChangeType)
|
||||
assert.Equal(t, "x-extension", extChanges.ExtensionChanges.Changes[0].Property)
|
||||
}
|
||||
|
||||
func TestCompareInfo_ExtensionRemoved(t *testing.T) {
|
||||
|
||||
left := `title: a nice spec
|
||||
version: '1.2.3'
|
||||
x-extension: extension
|
||||
`
|
||||
|
||||
right := `title: a nice spec
|
||||
version: '1.2.3'
|
||||
`
|
||||
|
||||
var lNode, rNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(left), &lNode)
|
||||
_ = yaml.Unmarshal([]byte(right), &rNode)
|
||||
|
||||
// create low level objects
|
||||
var lDoc base.Info
|
||||
var rDoc base.Info
|
||||
_ = low.BuildModel(lNode.Content[0], &lDoc)
|
||||
_ = low.BuildModel(rNode.Content[0], &rDoc)
|
||||
_ = lDoc.Build(nil, lNode.Content[0], nil)
|
||||
_ = rDoc.Build(nil, rNode.Content[0], nil)
|
||||
|
||||
// compare.
|
||||
extChanges := CompareInfo(&lDoc, &rDoc)
|
||||
assert.Equal(t, 1, extChanges.TotalChanges())
|
||||
assert.Len(t, extChanges.GetAllChanges(), 1)
|
||||
assert.Equal(t, ObjectRemoved, extChanges.ExtensionChanges.Changes[0].ChangeType)
|
||||
assert.Equal(t, "x-extension", extChanges.ExtensionChanges.Changes[0].Property)
|
||||
}
|
||||
|
||||
func TestCompareInfo_ExtensionModified(t *testing.T) {
|
||||
|
||||
left := `title: a nice spec
|
||||
version: '1.2.3'
|
||||
x-extension: original extension
|
||||
`
|
||||
|
||||
right := `title: a nice spec
|
||||
version: '1.2.3'
|
||||
x-extension: new extension
|
||||
`
|
||||
|
||||
var lNode, rNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(left), &lNode)
|
||||
_ = yaml.Unmarshal([]byte(right), &rNode)
|
||||
|
||||
// create low level objects
|
||||
var lDoc base.Info
|
||||
var rDoc base.Info
|
||||
_ = low.BuildModel(lNode.Content[0], &lDoc)
|
||||
_ = low.BuildModel(rNode.Content[0], &rDoc)
|
||||
_ = lDoc.Build(nil, lNode.Content[0], nil)
|
||||
_ = rDoc.Build(nil, rNode.Content[0], nil)
|
||||
|
||||
// compare.
|
||||
extChanges := CompareInfo(&lDoc, &rDoc)
|
||||
assert.Equal(t, 1, extChanges.TotalChanges())
|
||||
assert.Len(t, extChanges.GetAllChanges(), 1)
|
||||
assert.Equal(t, Modified, extChanges.ExtensionChanges.Changes[0].ChangeType)
|
||||
assert.Equal(t, "x-extension", extChanges.ExtensionChanges.Changes[0].Property)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user