Skip to content

Commit

Permalink
use ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven committed Jul 3, 2024
1 parent acf9bfe commit 583212b
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 195 deletions.
61 changes: 30 additions & 31 deletions checker/check_request_property_pattern_added_or_changed.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package checker

import (
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand Down Expand Up @@ -36,47 +35,47 @@ func RequestPropertyPatternUpdatedCheck(diffReport *diff.Diff, operationsSources
return
}

source := (*operationsSources)[operationItem.Revision]
propName := propertyFullName(propertyPath, propertyName)

if patternDiff.To == "" {
result = append(result, ApiChange{
Id: RequestPropertyPatternRemovedId,
Level: INFO,
Args: []any{patternDiff.From, propName},
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: load.NewSource(source),
})
result = append(result, NewApiChange(
RequestPropertyPatternRemovedId,
INFO,
[]any{patternDiff.From, propName},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))
} else if patternDiff.From == "" {
result = append(result, ApiChange{
Id: RequestPropertyPatternAddedId,
Level: WARN,
Args: []any{patternDiff.To, propName},
Comment: PatternChangedCommentId,
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: load.NewSource(source),
})
result = append(result, NewApiChange(
RequestPropertyPatternAddedId,
WARN,
[]any{patternDiff.To, propName},
PatternChangedCommentId,
operationsSources,
operationItem.Revision,
operation,
path,
))
} else {
level := WARN
comment := PatternChangedCommentId
if patternDiff.To == ".*" {
level = INFO
comment = ""
}
result = append(result, ApiChange{
Id: RequestPropertyPatternChangedId,
Level: level,
Args: []any{propName, patternDiff.From, patternDiff.To},
Comment: comment,
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: load.NewSource(source),
})
result = append(result, NewApiChange(
RequestPropertyPatternChangedId,
level,
[]any{propName, patternDiff.From, patternDiff.To},
comment,
operationsSources,
operationItem.Revision,
operation,
path,
))
}
})
}
Expand Down
59 changes: 30 additions & 29 deletions checker/check_request_property_required_updated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package checker

import (
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand All @@ -21,7 +20,6 @@ func RequestPropertyRequiredUpdatedCheck(diffReport *diff.Diff, operationsSource
continue
}
for operation, operationItem := range pathItem.OperationsDiff.Modified {
source := (*operationsSources)[operationItem.Revision]

if operationItem.RequestBodyDiff == nil ||
operationItem.RequestBodyDiff.ContentDiff == nil ||
Expand All @@ -42,42 +40,45 @@ func RequestPropertyRequiredUpdatedCheck(diffReport *diff.Diff, operationsSource
}

if schemaDiff.Revision.Properties[changedRequiredPropertyName].Value.Default == nil {
result = append(result, ApiChange{
Id: RequestPropertyBecameRequiredId,
Level: ERR,
Args: []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))},
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: load.NewSource(source),
})
result = append(result, NewApiChange(
RequestPropertyBecameRequiredId,
ERR,
[]any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))
} else {
// property has a default value, so making it required is not a breaking change
result = append(result, ApiChange{
Id: RequestPropertyBecameRequiredWithDefaultId,
Level: INFO,
Args: []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))},
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: load.NewSource(source),
})
result = append(result, NewApiChange(
RequestPropertyBecameRequiredWithDefaultId,
INFO,
[]any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))
}
}
for _, changedRequiredPropertyName := range schemaDiff.RequiredDiff.Deleted {
if !changedRequiredPropertyRelevant(schemaDiff, changedRequiredPropertyName) {
continue
}

result = append(result, ApiChange{
Id: RequestPropertyBecameOptionalId,
Level: INFO,
Args: []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))},
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: load.NewSource(source),
})
result = append(result, NewApiChange(
RequestPropertyBecameOptionalId,
INFO,
[]any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))
}
}
}
Expand Down
40 changes: 20 additions & 20 deletions checker/check_request_property_type_changed.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package checker

import (
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand All @@ -25,7 +24,6 @@ func RequestPropertyTypeChangedCheck(diffReport *diff.Diff, operationsSources *d
operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil {
continue
}
source := (*operationsSources)[operationItem.Revision]

modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified
for mediaType, mediaTypeDiff := range modifiedMediaTypes {
Expand All @@ -39,15 +37,16 @@ func RequestPropertyTypeChangedCheck(diffReport *diff.Diff, operationsSources *d

if !typeDiff.Empty() || !formatDiff.Empty() {

result = append(result, ApiChange{
Id: RequestBodyTypeChangedId,
Level: conditionalError(breakingTypeFormatChangedInRequestProperty(typeDiff, formatDiff, mediaType, schemaDiff), INFO),
Args: []any{getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff)},
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: load.NewSource(source),
})
result = append(result, NewApiChange(
RequestBodyTypeChangedId,
conditionalError(breakingTypeFormatChangedInRequestProperty(typeDiff, formatDiff, mediaType, schemaDiff), INFO),
[]any{getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff)},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))
}

CheckModifiedPropertiesDiff(
Expand All @@ -65,15 +64,16 @@ func RequestPropertyTypeChangedCheck(diffReport *diff.Diff, operationsSources *d

if !typeDiff.Empty() || !formatDiff.Empty() {

result = append(result, ApiChange{
Id: RequestPropertyTypeChangedId,
Level: conditionalError(breakingTypeFormatChangedInRequestProperty(typeDiff, formatDiff, mediaType, schemaDiff), INFO),
Args: []any{propertyFullName(propertyPath, propertyName), getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff)},
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: load.NewSource(source),
})
result = append(result, NewApiChange(
RequestPropertyTypeChangedId,
conditionalError(breakingTypeFormatChangedInRequestProperty(typeDiff, formatDiff, mediaType, schemaDiff), INFO),
[]any{propertyFullName(propertyPath, propertyName), getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff)},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))
}
})
}
Expand Down
80 changes: 41 additions & 39 deletions checker/check_request_property_updated.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package checker
import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
"golang.org/x/exp/slices"
)

Expand Down Expand Up @@ -35,22 +34,22 @@ func RequestPropertyUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.
mediaTypeDiff.SchemaDiff,
func(propertyPath string, propertyName string, propertyItem *openapi3.Schema, parent *diff.SchemaDiff) {
if !propertyItem.ReadOnly {
source := (*operationsSources)[operationItem.Revision]
result = append(result, ApiChange{
Id: RequestPropertyRemovedId,
Level: WARN,
Args: []any{propertyFullName(propertyPath, propertyName)},
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: load.NewSource(source),
})

result = append(result, NewApiChange(
RequestPropertyRemovedId,
WARN,
[]any{propertyFullName(propertyPath, propertyName)},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))
}
})
CheckAddedPropertiesDiff(
mediaTypeDiff.SchemaDiff,
func(propertyPath string, propertyName string, propertyItem *openapi3.Schema, parent *diff.SchemaDiff) {
source := (*operationsSources)[operationItem.Revision]
if propertyItem.ReadOnly {
return
}
Expand All @@ -59,36 +58,39 @@ func RequestPropertyUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.

if slices.Contains(parent.Revision.Required, propertyName) {
if propertyItem.Default == nil {
result = append(result, ApiChange{
Id: NewRequiredRequestPropertyId,
Level: ERR,
Args: []any{propName},
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: load.NewSource(source),
})
result = append(result, NewApiChange(
NewRequiredRequestPropertyId,
ERR,
[]any{propName},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))
} else {
result = append(result, ApiChange{
Id: NewRequiredRequestPropertyWithDefaultId,
Level: INFO,
Args: []any{propName},
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: load.NewSource(source),
})
result = append(result, NewApiChange(
NewRequiredRequestPropertyWithDefaultId,
INFO,
[]any{propName},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))
}
} else {
result = append(result, ApiChange{
Id: NewOptionalRequestPropertyId,
Level: INFO,
Args: []any{propName},
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: load.NewSource(source),
})
result = append(result, NewApiChange(
NewOptionalRequestPropertyId,
INFO,
[]any{propName},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))
}
})
}
Expand Down
Loading

0 comments on commit 583212b

Please sign in to comment.