Added what-changed documentation to methods and structs.

Signed-off-by: Dave Shanley <dave@quobix.com>
This commit is contained in:
Dave Shanley
2022-11-21 10:44:04 -05:00
parent 3ad8ec3d43
commit 62d580e671
15 changed files with 95 additions and 22 deletions

View File

@@ -94,6 +94,8 @@ type Change struct {
// PropertyChanges holds a slice of Change pointers // PropertyChanges holds a slice of Change pointers
type PropertyChanges struct { type PropertyChanges struct {
//Total *int `json:"total,omitempty" yaml:"total,omitempty"`
//Breaking *int `json:"breaking,omitempty" yaml:"breaking,omitempty"`
Changes []*Change `json:"changes,omitempty" yaml:"changes,omitempty"` Changes []*Change `json:"changes,omitempty" yaml:"changes,omitempty"`
} }

View File

@@ -151,7 +151,8 @@ func (o *OAuthFlowChanges) TotalBreakingChanges() int {
return o.PropertyChanges.TotalBreakingChanges() return o.PropertyChanges.TotalBreakingChanges()
} }
// CompareOAuthFlow checks a left and a right OAuthFlow object // CompareOAuthFlow checks a left and a right OAuthFlow object for changes. If found, returns a pointer to
// an OAuthFlowChanges instance, or nil if nothing is found.
func CompareOAuthFlow(l, r *v3.OAuthFlow) *OAuthFlowChanges { func CompareOAuthFlow(l, r *v3.OAuthFlow) *OAuthFlowChanges {
if low.AreEqual(l, r) { if low.AreEqual(l, r) {
return nil return nil

View File

@@ -14,6 +14,7 @@ import (
"strings" "strings"
) )
// OperationChanges represent changes made between two Swagger or OpenAPI Operation objects.
type OperationChanges struct { type OperationChanges struct {
PropertyChanges PropertyChanges
ExternalDocChanges *ExternalDocChanges `json:"externalDoc,omitempty" yaml:"externalDoc,omitempty"` ExternalDocChanges *ExternalDocChanges `json:"externalDoc,omitempty" yaml:"externalDoc,omitempty"`
@@ -21,13 +22,14 @@ type OperationChanges struct {
ResponsesChanges *ResponsesChanges `json:"responses,omitempty" yaml:"responses,omitempty"` ResponsesChanges *ResponsesChanges `json:"responses,omitempty" yaml:"responses,omitempty"`
SecurityRequirementChanges []*SecurityRequirementChanges `json:"securityRequirements,omitempty" yaml:"securityRequirements,omitempty"` SecurityRequirementChanges []*SecurityRequirementChanges `json:"securityRequirements,omitempty" yaml:"securityRequirements,omitempty"`
// v3 // OpenAPI 3+ only changes
RequestBodyChanges *RequestBodyChanges `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"` RequestBodyChanges *RequestBodyChanges `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"`
ServerChanges []*ServerChanges `json:"servers,omitempty" yaml:"servers,omitempty"` ServerChanges []*ServerChanges `json:"servers,omitempty" yaml:"servers,omitempty"`
ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"` ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"`
CallbackChanges map[string]*CallbackChanges `json:"callbacks,omitempty" yaml:"callbacks,omitempty"` CallbackChanges map[string]*CallbackChanges `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
} }
// TotalChanges returns the total number of changes made between two Swagger or OpenAPI Operation objects.
func (o *OperationChanges) TotalChanges() int { func (o *OperationChanges) TotalChanges() int {
c := o.PropertyChanges.TotalChanges() c := o.PropertyChanges.TotalChanges()
if o.ExternalDocChanges != nil { if o.ExternalDocChanges != nil {
@@ -57,6 +59,8 @@ func (o *OperationChanges) TotalChanges() int {
return c return c
} }
// TotalBreakingChanges returns the total number of breaking changes made between two Swagger
// or OpenAPI Operation objects.
func (o *OperationChanges) TotalBreakingChanges() int { func (o *OperationChanges) TotalBreakingChanges() int {
c := o.PropertyChanges.TotalBreakingChanges() c := o.PropertyChanges.TotalBreakingChanges()
if o.ExternalDocChanges != nil { if o.ExternalDocChanges != nil {
@@ -84,6 +88,7 @@ func (o *OperationChanges) TotalBreakingChanges() int {
return c return c
} }
// check for properties shared between operations objects.
func addSharedOperationProperties(left, right low.SharedOperations, changes *[]*Change) []*PropertyCheck { func addSharedOperationProperties(left, right low.SharedOperations, changes *[]*Change) []*PropertyCheck {
var props []*PropertyCheck var props []*PropertyCheck
@@ -112,6 +117,7 @@ func addSharedOperationProperties(left, right low.SharedOperations, changes *[]*
return props return props
} }
// check shared objects
func compareSharedOperationObjects(l, r low.SharedOperations, changes *[]*Change, opChanges *OperationChanges) { func compareSharedOperationObjects(l, r low.SharedOperations, changes *[]*Change, opChanges *OperationChanges) {
// external docs // external docs
@@ -150,6 +156,8 @@ func compareSharedOperationObjects(l, r low.SharedOperations, changes *[]*Change
} }
// CompareOperations compares a left and right Swagger or OpenAPI Operation object. If changes are found, returns
// a pointer to an OperationChanges instance, or nil if nothing is found.
func CompareOperations(l, r any) *OperationChanges { func CompareOperations(l, r any) *OperationChanges {
var changes []*Change var changes []*Change
@@ -373,6 +381,7 @@ func CompareOperations(l, r any) *OperationChanges {
return oc return oc
} }
// check servers property
func checkServers(lServers, rServers low.NodeReference[[]low.ValueReference[*v3.Server]]) []*ServerChanges { func checkServers(lServers, rServers low.NodeReference[[]low.ValueReference[*v3.Server]]) []*ServerChanges {
var serverChanges []*ServerChanges var serverChanges []*ServerChanges
@@ -460,6 +469,7 @@ func checkServers(lServers, rServers low.NodeReference[[]low.ValueReference[*v3.
return serverChanges return serverChanges
} }
// check security property.
func checkSecurity(lSecurity, rSecurity low.NodeReference[[]low.ValueReference[*base.SecurityRequirement]], func checkSecurity(lSecurity, rSecurity low.NodeReference[[]low.ValueReference[*base.SecurityRequirement]],
changes *[]*Change, oc any) { changes *[]*Change, oc any) {

View File

@@ -12,15 +12,16 @@ import (
"reflect" "reflect"
) )
// ParameterChanges represents changes found between Swagger or OpenAPI Parameter objects.
type ParameterChanges struct { type ParameterChanges struct {
PropertyChanges PropertyChanges
SchemaChanges *SchemaChanges `json:"schemas,omitempty" yaml:"schemas,omitempty"` SchemaChanges *SchemaChanges `json:"schemas,omitempty" yaml:"schemas,omitempty"`
ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"` ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"`
// v2 change types // Swagger supports Items.
ItemsChanges *ItemsChanges `json:"items,omitempty" yaml:"items,omitempty"` ItemsChanges *ItemsChanges `json:"items,omitempty" yaml:"items,omitempty"`
// v3 change types // OpenAPI supports examples and content types.
ExamplesChanges map[string]*ExampleChanges `json:"examples,omitempty" yaml:"examples,omitempty"` ExamplesChanges map[string]*ExampleChanges `json:"examples,omitempty" yaml:"examples,omitempty"`
ContentChanges map[string]*MediaTypeChanges `json:"content,omitempty" yaml:"content,omitempty"` ContentChanges map[string]*MediaTypeChanges `json:"content,omitempty" yaml:"content,omitempty"`
} }
@@ -191,14 +192,13 @@ func addCommonParameterProperties(left, right low.SharedParameters, changes *[]*
return props return props
} }
// CompareParametersV3 is amn OpenAPI type safe proxy for CompareParameters
func CompareParametersV3(l, r *v3.Parameter) *ParameterChanges { func CompareParametersV3(l, r *v3.Parameter) *ParameterChanges {
return CompareParameters(l, r) return CompareParameters(l, r)
} }
func CompareParametersV2(l, r *v2.Parameter) *ParameterChanges { // CompareParameters compares a left and right Swagger or OpenAPI Parameter object for any changes. If found returns
return CompareParameters(l, r) // a pointer to ParameterChanges. If nothing is found, returns nil.
}
func CompareParameters(l, r any) *ParameterChanges { func CompareParameters(l, r any) *ParameterChanges {
var changes []*Change var changes []*Change

View File

@@ -10,6 +10,7 @@ import (
"reflect" "reflect"
) )
// PathItemChanges represents changes found between to Swagger or OpenAPI PathItem object.
type PathItemChanges struct { type PathItemChanges struct {
PropertyChanges PropertyChanges
GetChanges *OperationChanges `json:"get,omitempty" yaml:"get,omitempty"` GetChanges *OperationChanges `json:"get,omitempty" yaml:"get,omitempty"`
@@ -25,6 +26,7 @@ type PathItemChanges struct {
ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"` ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"`
} }
// TotalChanges returns the total number of changes found between two Swagger or OpenAPI PathItems
func (p *PathItemChanges) TotalChanges() int { func (p *PathItemChanges) TotalChanges() int {
c := p.PropertyChanges.TotalChanges() c := p.PropertyChanges.TotalChanges()
if p.GetChanges != nil { if p.GetChanges != nil {
@@ -63,6 +65,7 @@ func (p *PathItemChanges) TotalChanges() int {
return c return c
} }
// TotalBreakingChanges returns the total number of breaking changes found between two Swagger or OpenAPI PathItems
func (p *PathItemChanges) TotalBreakingChanges() int { func (p *PathItemChanges) TotalBreakingChanges() int {
c := p.PropertyChanges.TotalBreakingChanges() c := p.PropertyChanges.TotalBreakingChanges()
if p.GetChanges != nil { if p.GetChanges != nil {
@@ -103,10 +106,13 @@ type opCheck struct {
changes *OperationChanges changes *OperationChanges
} }
// ComparePathItemsV3 is an OpenAPI typesafe proxy method for ComparePathItems
func ComparePathItemsV3(l, r *v3.PathItem) *PathItemChanges { func ComparePathItemsV3(l, r *v3.PathItem) *PathItemChanges {
return ComparePathItems(l, r) return ComparePathItems(l, r)
} }
// ComparePathItems compare a left and right Swagger or OpenAPI PathItem object for changes. If found, returns
// a pointer to PathItemChanges, or returns nil if nothing is found.
func ComparePathItems(l, r any) *PathItemChanges { func ComparePathItems(l, r any) *PathItemChanges {
var changes []*Change var changes []*Change

View File

@@ -11,12 +11,14 @@ import (
"sync" "sync"
) )
// PathsChanges represents changes found between two Swagger or OpenAPI Paths Objects.
type PathsChanges struct { type PathsChanges struct {
PropertyChanges PropertyChanges
PathItemsChanges map[string]*PathItemChanges `json:"pathItems,omitempty" yaml:"pathItems,omitempty"` PathItemsChanges map[string]*PathItemChanges `json:"pathItems,omitempty" yaml:"pathItems,omitempty"`
ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"` ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"`
} }
// TotalChanges returns the total number of changes between two Swagger or OpenAPI Paths Objects
func (p *PathsChanges) TotalChanges() int { func (p *PathsChanges) TotalChanges() int {
c := p.PropertyChanges.TotalChanges() c := p.PropertyChanges.TotalChanges()
for k := range p.PathItemsChanges { for k := range p.PathItemsChanges {
@@ -28,6 +30,7 @@ func (p *PathsChanges) TotalChanges() int {
return c return c
} }
// TotalBreakingChanges returns tht total number of changes found between two Swagger or OpenAPI Path Objects
func (p *PathsChanges) TotalBreakingChanges() int { func (p *PathsChanges) TotalBreakingChanges() int {
c := p.PropertyChanges.TotalBreakingChanges() c := p.PropertyChanges.TotalBreakingChanges()
for k := range p.PathItemsChanges { for k := range p.PathItemsChanges {
@@ -36,6 +39,8 @@ func (p *PathsChanges) TotalBreakingChanges() int {
return c return c
} }
// ComparePaths compares a left and right Swagger or OpenAPI Paths Object for changes. If found, returns a pointer
// to a PathsChanges instance. Returns nil if nothing is found.
func ComparePaths(l, r any) *PathsChanges { func ComparePaths(l, r any) *PathsChanges {
var changes []*Change var changes []*Change

View File

@@ -8,12 +8,14 @@ import (
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
) )
// RequestBodyChanges represents changes made between two OpenAPI RequestBody Objects
type RequestBodyChanges struct { type RequestBodyChanges struct {
PropertyChanges PropertyChanges
ContentChanges map[string]*MediaTypeChanges `json:"content,omitempty" yaml:"content,omitempty"` ContentChanges map[string]*MediaTypeChanges `json:"content,omitempty" yaml:"content,omitempty"`
ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"` ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"`
} }
// TotalChanges returns the total number of changes found between two OpenAPI RequestBody objects
func (rb *RequestBodyChanges) TotalChanges() int { func (rb *RequestBodyChanges) TotalChanges() int {
c := rb.PropertyChanges.TotalChanges() c := rb.PropertyChanges.TotalChanges()
for k := range rb.ContentChanges { for k := range rb.ContentChanges {
@@ -25,6 +27,7 @@ func (rb *RequestBodyChanges) TotalChanges() int {
return c return c
} }
// TotalBreakingChanges returns the total number of breaking changes found between OpenAPI RequestBody objects
func (rb *RequestBodyChanges) TotalBreakingChanges() int { func (rb *RequestBodyChanges) TotalBreakingChanges() int {
c := rb.PropertyChanges.TotalBreakingChanges() c := rb.PropertyChanges.TotalBreakingChanges()
for k := range rb.ContentChanges { for k := range rb.ContentChanges {
@@ -33,6 +36,8 @@ func (rb *RequestBodyChanges) TotalBreakingChanges() int {
return c return c
} }
// CompareRequestBodies compares a left and right OpenAPI RequestBody object for changes. If found returns a pointer
// to a RequestBodyChanges instance. Returns nil if nothing was found.
func CompareRequestBodies(l, r *v3.RequestBody) *RequestBodyChanges { func CompareRequestBodies(l, r *v3.RequestBody) *RequestBodyChanges {
if low.AreEqual(l, r) { if low.AreEqual(l, r) {
return nil return nil

View File

@@ -10,21 +10,23 @@ import (
"reflect" "reflect"
) )
// ResponseChanges represents changes found between two Swagger or OpenAPI Response objects.
type ResponseChanges struct { type ResponseChanges struct {
PropertyChanges PropertyChanges
ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"` ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"`
HeadersChanges map[string]*HeaderChanges `json:"headers,omitempty" yaml:"headers,omitempty"` HeadersChanges map[string]*HeaderChanges `json:"headers,omitempty" yaml:"headers,omitempty"`
// v2 // Swagger Response Properties.
SchemaChanges *SchemaChanges `json:"schemas,omitempty" yaml:"schemas,omitempty"` SchemaChanges *SchemaChanges `json:"schemas,omitempty" yaml:"schemas,omitempty"`
ExamplesChanges *ExamplesChanges `json:"examples,omitempty" yaml:"examples,omitempty"` ExamplesChanges *ExamplesChanges `json:"examples,omitempty" yaml:"examples,omitempty"`
// v3 // OpenAPI Response Properties.
ContentChanges map[string]*MediaTypeChanges `json:"content,omitempty" yaml:"content,omitempty"` ContentChanges map[string]*MediaTypeChanges `json:"content,omitempty" yaml:"content,omitempty"`
LinkChanges map[string]*LinkChanges `json:"links,omitempty" yaml:"links,omitempty"` LinkChanges map[string]*LinkChanges `json:"links,omitempty" yaml:"links,omitempty"`
ServerChanges *ServerChanges `json:"server,omitempty" yaml:"server,omitempty"` ServerChanges *ServerChanges `json:"server,omitempty" yaml:"server,omitempty"`
} }
// TotalChanges returns the total number of changes found between two Swagger or OpenAPI Response Objects
func (r *ResponseChanges) TotalChanges() int { func (r *ResponseChanges) TotalChanges() int {
c := r.PropertyChanges.TotalChanges() c := r.PropertyChanges.TotalChanges()
if r.ExtensionChanges != nil { if r.ExtensionChanges != nil {
@@ -48,6 +50,8 @@ func (r *ResponseChanges) TotalChanges() int {
return c return c
} }
// TotalBreakingChanges returns the total number of breaking changes found between two swagger or OpenAPI
// Response Objects
func (r *ResponseChanges) TotalBreakingChanges() int { func (r *ResponseChanges) TotalBreakingChanges() int {
c := r.PropertyChanges.TotalBreakingChanges() c := r.PropertyChanges.TotalBreakingChanges()
if r.SchemaChanges != nil { if r.SchemaChanges != nil {
@@ -65,14 +69,18 @@ func (r *ResponseChanges) TotalBreakingChanges() int {
return c return c
} }
// CompareResponseV2 is a Swagger type safe proxy for CompareResponse
func CompareResponseV2(l, r *v2.Response) *ResponseChanges { func CompareResponseV2(l, r *v2.Response) *ResponseChanges {
return CompareResponse(l, r) return CompareResponse(l, r)
} }
// CompareResponseV3 is an OpenAPI type safe proxy for CompareResponse
func CompareResponseV3(l, r *v3.Response) *ResponseChanges { func CompareResponseV3(l, r *v3.Response) *ResponseChanges {
return CompareResponse(l, r) return CompareResponse(l, r)
} }
// CompareResponse compares a left and right Swagger or OpenAPI Response object. If anything is found
// a pointer to a ResponseChanges is returned, otherwise it returns nil.
func CompareResponse(l, r any) *ResponseChanges { func CompareResponse(l, r any) *ResponseChanges {
var changes []*Change var changes []*Change

View File

@@ -10,6 +10,7 @@ import (
"reflect" "reflect"
) )
// ResponsesChanges represents changes made between two Swagger or OpenAPI Responses objects.
type ResponsesChanges struct { type ResponsesChanges struct {
PropertyChanges PropertyChanges
ResponseChanges map[string]*ResponseChanges `json:"response,omitempty" yaml:"response,omitempty"` ResponseChanges map[string]*ResponseChanges `json:"response,omitempty" yaml:"response,omitempty"`
@@ -17,6 +18,7 @@ type ResponsesChanges struct {
ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"` ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"`
} }
// TotalChanges returns the total number of changes found between two Swagger or OpenAPI Responses objects
func (r *ResponsesChanges) TotalChanges() int { func (r *ResponsesChanges) TotalChanges() int {
c := r.PropertyChanges.TotalChanges() c := r.PropertyChanges.TotalChanges()
for k := range r.ResponseChanges { for k := range r.ResponseChanges {
@@ -31,6 +33,8 @@ func (r *ResponsesChanges) TotalChanges() int {
return c return c
} }
// TotalBreakingChanges returns the total number of changes found between two Swagger or OpenAPI
// Responses Objects
func (r *ResponsesChanges) TotalBreakingChanges() int { func (r *ResponsesChanges) TotalBreakingChanges() int {
c := r.PropertyChanges.TotalBreakingChanges() c := r.PropertyChanges.TotalBreakingChanges()
for k := range r.ResponseChanges { for k := range r.ResponseChanges {
@@ -42,6 +46,8 @@ func (r *ResponsesChanges) TotalBreakingChanges() int {
return c return c
} }
// CompareResponses compares a left and right Swagger or OpenAPI Responses object for any changes. If found
// returns a pointer to ResponsesChanges, or returns nil.
func CompareResponses(l, r any) *ResponsesChanges { func CompareResponses(l, r any) *ResponsesChanges {
var changes []*Change var changes []*Change

View File

@@ -129,6 +129,8 @@ func (s *SchemaChanges) TotalBreakingChanges() int {
return t return t
} }
// CompareSchemas accepts a left and right SchemaProxy and checks for changes. If anything is found, returns
// a pointer to SchemaChanges, otherwise returns nil
func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges { func CompareSchemas(l, r *base.SchemaProxy) *SchemaChanges {
sc := new(SchemaChanges) sc := new(SchemaChanges)
var changes []*Change var changes []*Change

View File

@@ -9,11 +9,13 @@ import (
v3 "github.com/pb33f/libopenapi/datamodel/low/v3" v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
) )
// ScopesChanges represents changes between two Swagger Scopes Objects
type ScopesChanges struct { type ScopesChanges struct {
PropertyChanges PropertyChanges
ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"` ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"`
} }
// TotalChanges returns the total changes found between two Swagger Scopes objects.
func (s *ScopesChanges) TotalChanges() int { func (s *ScopesChanges) TotalChanges() int {
c := s.PropertyChanges.TotalChanges() c := s.PropertyChanges.TotalChanges()
if s.ExtensionChanges != nil { if s.ExtensionChanges != nil {
@@ -22,10 +24,13 @@ func (s *ScopesChanges) TotalChanges() int {
return c return c
} }
// TotalBreakingChanges returns the total number of breaking changes between two Swagger Scopes objects.
func (s *ScopesChanges) TotalBreakingChanges() int { func (s *ScopesChanges) TotalBreakingChanges() int {
return s.PropertyChanges.TotalBreakingChanges() return s.PropertyChanges.TotalBreakingChanges()
} }
// CompareScopes compares a left and right Swagger Scopes objects for changes. If anything is found, returns
// a pointer to ScopesChanges, or returns nil if nothing is found.
func CompareScopes(l, r *v2.Scopes) *ScopesChanges { func CompareScopes(l, r *v2.Scopes) *ScopesChanges {
if low.AreEqual(l, r) { if low.AreEqual(l, r) {
return nil return nil

View File

@@ -10,28 +10,23 @@ import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
// SecurityRequirementChanges represents changes found between two SecurityRequirement Objects.
type SecurityRequirementChanges struct { type SecurityRequirementChanges struct {
PropertyChanges PropertyChanges
} }
// TotalChanges returns the total number of changes between two SecurityRequirement Objects.
func (s *SecurityRequirementChanges) TotalChanges() int { func (s *SecurityRequirementChanges) TotalChanges() int {
return s.PropertyChanges.TotalChanges() return s.PropertyChanges.TotalChanges()
} }
// TotalBreakingChanges returns the total number of breaking changes between two SecurityRequirement Objects.
func (s *SecurityRequirementChanges) TotalBreakingChanges() int { func (s *SecurityRequirementChanges) TotalBreakingChanges() int {
return s.PropertyChanges.TotalBreakingChanges() return s.PropertyChanges.TotalBreakingChanges()
} }
func removedSecurityRequirement(vn *yaml.Node, name string, changes *[]*Change) { // CompareSecurityRequirement compares left and right SecurityRequirement objects for changes. If anything
CreateChange(changes, ObjectRemoved, v3.SecurityLabel, // is found, then a pointer to SecurityRequirementChanges is returned, otherwise nil.
vn, nil, true, name, nil)
}
func addedSecurityRequirement(vn *yaml.Node, name string, changes *[]*Change) {
CreateChange(changes, ObjectAdded, v3.SecurityLabel,
nil, vn, false, nil, name)
}
func CompareSecurityRequirement(l, r *base.SecurityRequirement) *SecurityRequirementChanges { func CompareSecurityRequirement(l, r *base.SecurityRequirement) *SecurityRequirementChanges {
var changes []*Change var changes []*Change
@@ -45,6 +40,17 @@ func CompareSecurityRequirement(l, r *base.SecurityRequirement) *SecurityRequire
return sc return sc
} }
func removedSecurityRequirement(vn *yaml.Node, name string, changes *[]*Change) {
CreateChange(changes, ObjectRemoved, v3.SecurityLabel,
vn, nil, true, name, nil)
}
func addedSecurityRequirement(vn *yaml.Node, name string, changes *[]*Change) {
CreateChange(changes, ObjectAdded, v3.SecurityLabel,
nil, vn, false, nil, name)
}
// tricky to do this correctly, this is my solution.
func checkSecurityRequirement(lSec, rSec map[low.KeyReference[string]]low.ValueReference[[]low.ValueReference[string]], func checkSecurityRequirement(lSec, rSec map[low.KeyReference[string]]low.ValueReference[[]low.ValueReference[string]],
changes *[]*Change) { changes *[]*Change) {

View File

@@ -10,15 +10,19 @@ import (
"reflect" "reflect"
) )
// SecuritySchemeChanges represents changes made between Swagger or OpenAPI SecurityScheme Objects.
type SecuritySchemeChanges struct { type SecuritySchemeChanges struct {
PropertyChanges PropertyChanges
ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"` ExtensionChanges *ExtensionChanges `json:"extensions,omitempty" yaml:"extensions,omitempty"`
// v3
// OpenAPI Version
OAuthFlowChanges *OAuthFlowsChanges `json:"oAuthFlow,omitempty" yaml:"oAuthFlow,omitempty"` OAuthFlowChanges *OAuthFlowsChanges `json:"oAuthFlow,omitempty" yaml:"oAuthFlow,omitempty"`
// v2
// Swagger Version
ScopesChanges *ScopesChanges `json:"scopes,omitempty" yaml:"scopes,omitempty"` ScopesChanges *ScopesChanges `json:"scopes,omitempty" yaml:"scopes,omitempty"`
} }
// TotalChanges represents total changes found between two Swagger or OpenAPI SecurityScheme instances.
func (ss *SecuritySchemeChanges) TotalChanges() int { func (ss *SecuritySchemeChanges) TotalChanges() int {
c := ss.PropertyChanges.TotalChanges() c := ss.PropertyChanges.TotalChanges()
if ss.OAuthFlowChanges != nil { if ss.OAuthFlowChanges != nil {
@@ -33,6 +37,7 @@ func (ss *SecuritySchemeChanges) TotalChanges() int {
return c return c
} }
// TotalBreakingChanges returns total number of breaking changes between two SecurityScheme Objects.
func (ss *SecuritySchemeChanges) TotalBreakingChanges() int { func (ss *SecuritySchemeChanges) TotalBreakingChanges() int {
c := ss.PropertyChanges.TotalBreakingChanges() c := ss.PropertyChanges.TotalBreakingChanges()
if ss.OAuthFlowChanges != nil { if ss.OAuthFlowChanges != nil {
@@ -44,14 +49,18 @@ func (ss *SecuritySchemeChanges) TotalBreakingChanges() int {
return c return c
} }
// CompareSecuritySchemesV2 is a Swagger type safe proxy for CompareSecuritySchemes
func CompareSecuritySchemesV2(l, r *v2.SecurityScheme) *SecuritySchemeChanges { func CompareSecuritySchemesV2(l, r *v2.SecurityScheme) *SecuritySchemeChanges {
return CompareSecuritySchemes(l, r) return CompareSecuritySchemes(l, r)
} }
// CompareSecuritySchemesV3 is an OpenAPI type safe proxt for CompareSecuritySchemes
func CompareSecuritySchemesV3(l, r *v3.SecurityScheme) *SecuritySchemeChanges { func CompareSecuritySchemesV3(l, r *v3.SecurityScheme) *SecuritySchemeChanges {
return CompareSecuritySchemes(l, r) return CompareSecuritySchemes(l, r)
} }
// CompareSecuritySchemes compares left and right Swagger or OpenAPI Security Scheme objects for changes.
// If anything is found, returns a pointer to *SecuritySchemeChanges or nil if nothing is found.
func CompareSecuritySchemes(l, r any) *SecuritySchemeChanges { func CompareSecuritySchemes(l, r any) *SecuritySchemeChanges {
var props []*PropertyCheck var props []*PropertyCheck

View File

@@ -8,11 +8,13 @@ import (
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
) )
// ServerChanges represents changes found between two OpenAPI Server Objects
type ServerChanges struct { type ServerChanges struct {
PropertyChanges PropertyChanges
ServerVariableChanges map[string]*ServerVariableChanges `json:"serverVariables,omitempty" yaml:"serverVariables,omitempty"` ServerVariableChanges map[string]*ServerVariableChanges `json:"serverVariables,omitempty" yaml:"serverVariables,omitempty"`
} }
// TotalChanges returns total changes found between two OpenAPI Server Objects
func (s *ServerChanges) TotalChanges() int { func (s *ServerChanges) TotalChanges() int {
c := s.PropertyChanges.TotalChanges() c := s.PropertyChanges.TotalChanges()
for k := range s.ServerVariableChanges { for k := range s.ServerVariableChanges {
@@ -21,6 +23,7 @@ func (s *ServerChanges) TotalChanges() int {
return c return c
} }
// TotalBreakingChanges returns the total number of breaking changes found between two OpenAPI Server objects.
func (s *ServerChanges) TotalBreakingChanges() int { func (s *ServerChanges) TotalBreakingChanges() int {
c := s.PropertyChanges.TotalBreakingChanges() c := s.PropertyChanges.TotalBreakingChanges()
for k := range s.ServerVariableChanges { for k := range s.ServerVariableChanges {
@@ -29,6 +32,8 @@ func (s *ServerChanges) TotalBreakingChanges() int {
return c return c
} }
// CompareServers compares two OpenAPI Server objects for any changes. If anything is found, returns a pointer
// to a ServerChanges instance, or returns nil if nothing is found.
func CompareServers(l, r *v3.Server) *ServerChanges { func CompareServers(l, r *v3.Server) *ServerChanges {
if low.AreEqual(l, r) { if low.AreEqual(l, r) {
return nil return nil

View File

@@ -8,10 +8,13 @@ import (
"github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/datamodel/low/v3"
) )
// ServerVariableChanges represents changes found between two OpenAPI ServerVariable Objects
type ServerVariableChanges struct { type ServerVariableChanges struct {
PropertyChanges PropertyChanges
} }
// CompareServerVariables compares a left and right OpenAPI ServerVariable object for changes.
// If anything is found, returns a pointer to a ServerVariableChanges instance, otherwise returns nil.
func CompareServerVariables(l, r *v3.ServerVariable) *ServerVariableChanges { func CompareServerVariables(l, r *v3.ServerVariable) *ServerVariableChanges {
if low.AreEqual(l, r) { if low.AreEqual(l, r) {
return nil return nil