Skip to content

Commit

Permalink
Turn Localizer into an interface (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf authored Aug 16, 2023
1 parent ce22c9d commit b9a94b9
Show file tree
Hide file tree
Showing 100 changed files with 295 additions and 450 deletions.
34 changes: 17 additions & 17 deletions BREAKING-CHANGES-EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ These examples are automatically generated from unit tests.
[changing response's embedded property schema type from string/none to integer/int32 is breaking](checker/checker_breaking_response_type_changed_test.go?plain=1#L108)
[deleting a media-type from response is breaking](checker/checker_breaking_test.go?plain=1#L429)
[deleting a path is breaking](checker/checker_breaking_test.go?plain=1#L43)
[deleting a path with some operations having sunset date in the future is breaking](checker/checker_deprecation_test.go?plain=1#L273)
[deleting a path with some operations having sunset date in the future is breaking](checker/checker_deprecation_test.go?plain=1#L272)
[deleting a required property in request is breaking with warn](checker/checker_breaking_property_test.go?plain=1#L368)
[deleting a required property in response body is breaking](checker/checker_breaking_property_test.go?plain=1#L416)
[deleting a required property under AllOf in response body is breaking](checker/checker_breaking_property_test.go?plain=1#L446)
[deleting a required property within another property in request is breaking with warn](checker/checker_breaking_property_test.go?plain=1#L385)
[deleting an enum value is breaking](checker/checker_breaking_test.go?plain=1#L103)
[deleting an operation before sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L35)
[deleting an operation before sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L34)
[deleting an operation is breaking](checker/checker_breaking_test.go?plain=1#L50)
[deleting an operation without sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L52)
[deleting sunset header for a deprecated endpoint is breaking](checker/checker_deprecation_test.go?plain=1#L290)
[deprecating an operation with a deprecation policy and sunset date before required deprecation period is breaking](checker/checker_deprecation_test.go?plain=1#L218)
[deprecating an operation with a deprecation policy but without specifying sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L84)
[deleting an operation without sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L51)
[deleting sunset header for a deprecated endpoint is breaking](checker/checker_deprecation_test.go?plain=1#L289)
[deprecating an operation with a deprecation policy and sunset date before required deprecation period is breaking](checker/checker_deprecation_test.go?plain=1#L217)
[deprecating an operation with a deprecation policy but without specifying sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L83)
[increasing max length in response is breaking](checker/checker_breaking_min_max_test.go?plain=1#L93)
[increasing min items in request is breaking](checker/checker_breaking_min_max_test.go?plain=1#L236)
[modifying a pattern in a schema is breaking](checker/checker_breaking_test.go?plain=1#L491)
Expand All @@ -74,8 +74,8 @@ These examples are automatically generated from unit tests.
[removing an existing response with successful status is breaking](checker/checker_breaking_test.go?plain=1#L246)
[removing an schema object from components is breaking (optional)](checker/checker_breaking_test.go?plain=1#L610)
[removing the default value of an optional request parameter is breaking](checker/checker_breaking_test.go?plain=1#L573)
[removing the path without a deprecation policy and without specifying sunset date is breaking if some APIs are not alpha stability level](checker/checker_deprecation_test.go?plain=1#L137)
[removing the path without a deprecation policy and without specifying sunset date is breaking if some APIs are not draft stability level](checker/checker_deprecation_test.go?plain=1#L191)
[removing the path without a deprecation policy and without specifying sunset date is breaking if some APIs are not alpha stability level](checker/checker_deprecation_test.go?plain=1#L136)
[removing the path without a deprecation policy and without specifying sunset date is breaking if some APIs are not draft stability level](checker/checker_deprecation_test.go?plain=1#L190)
[removing/updating a property enum in response is breaking (optional)](checker/checker_breaking_test.go?plain=1#L324)
[removing/updating a tag is breaking (optional)](checker/checker_breaking_test.go?plain=1#L341)
[removing/updating an enum in request body is breaking (optional)](checker/checker_breaking_test.go?plain=1#L302)
Expand Down Expand Up @@ -113,17 +113,17 @@ These examples are automatically generated from unit tests.
[changing response's body schema type from number/none to integer/int32 is not breaking](checker/checker_breaking_response_type_changed_test.go?plain=1#L89)
[changing servers is not breaking](checker/checker_not_breaking_test.go?plain=1#L253)
[deleting a non-required non-write-only property in response body is not breaking](checker/checker_breaking_property_test.go?plain=1#L531)
[deleting a path after sunset date of all contained operations is not breaking](checker/checker_deprecation_test.go?plain=1#L258)
[deleting a path after sunset date of all contained operations is not breaking](checker/checker_deprecation_test.go?plain=1#L257)
[deleting a pattern from a schema is not breaking](checker/checker_breaking_test.go?plain=1#L445)
[deleting a required write-only property in response body is not breaking](checker/checker_breaking_property_test.go?plain=1#L514)
[deleting a tag is not breaking](checker/checker_not_breaking_test.go?plain=1#L71)
[deleting an operation after sunset date is not breaking](checker/checker_deprecation_test.go?plain=1#L69)
[deleting an operation after sunset date is not breaking](checker/checker_deprecation_test.go?plain=1#L68)
[deprecating a header is not breaking](checker/checker_not_breaking_test.go?plain=1#L227)
[deprecating a parameter is not breaking](checker/checker_not_breaking_test.go?plain=1#L214)
[deprecating a schema is not breaking](checker/checker_not_breaking_test.go?plain=1#L240)
[deprecating an operation with a deprecation policy and sunset date after required deprecation period is not breaking](checker/checker_deprecation_test.go?plain=1#L237)
[deprecating an operation without a deprecation policy and without specifying sunset date is not breaking for draft level](checker/checker_deprecation_test.go?plain=1#L155)
[deprecating an operation without a deprecation policy and without specifying sunset date is not breaking](checker/checker_deprecation_test.go?plain=1#L103)
[deprecating an operation with a deprecation policy and sunset date after required deprecation period is not breaking](checker/checker_deprecation_test.go?plain=1#L236)
[deprecating an operation without a deprecation policy and without specifying sunset date is not breaking for draft level](checker/checker_deprecation_test.go?plain=1#L154)
[deprecating an operation without a deprecation policy and without specifying sunset date is not breaking](checker/checker_deprecation_test.go?plain=1#L102)
[increasing max length in request is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L76)
[increasing min items in response is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L250)
[modifying a pattern to ".*" in a schema is not breaking](checker/checker_breaking_test.go?plain=1#L523)
Expand All @@ -138,8 +138,8 @@ These examples are automatically generated from unit tests.
[reducing min length in request is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L48)
[removing an existing response with error status is not breaking](checker/checker_breaking_test.go?plain=1#L394)
[removing an existing response with unparseable status is not breaking](checker/checker_breaking_test.go?plain=1#L378)
[removing the path without a deprecation policy and without specifying sunset date is not breaking for alpha level](checker/checker_deprecation_test.go?plain=1#L118)
[removing the path without a deprecation policy and without specifying sunset date is not breaking for draft level](checker/checker_deprecation_test.go?plain=1#L172)
[removing the path without a deprecation policy and without specifying sunset date is not breaking for alpha level](checker/checker_deprecation_test.go?plain=1#L117)
[removing the path without a deprecation policy and without specifying sunset date is not breaking for draft level](checker/checker_deprecation_test.go?plain=1#L171)
[renaming a path parameter is not breaking](checker/checker_breaking_test.go?plain=1#L135)

## Examples of info-level changes for changelog
Expand Down Expand Up @@ -268,8 +268,8 @@ These examples are automatically generated from unit tests.
[increasing request property maximum value](checker/check-request-property-max-updated_test.go?plain=1#L37)
[new header, query and cookie request params](checker/check-new-request-non-path-parameter_test.go?plain=1#L11)
[new paths or path operations](checker/check-api-added_test.go?plain=1#L11)
[path operations that became deprecated](checker/checker_deprecation_test.go?plain=1#L324)
[path operations that were re-activated](checker/checker_deprecation_test.go?plain=1#L346)
[path operations that became deprecated](checker/checker_deprecation_test.go?plain=1#L323)
[path operations that were re-activated](checker/checker_deprecation_test.go?plain=1#L345)
[removing 'allOf' schema from the request body or request body property](checker/check-request-property-all-of-updated_test.go?plain=1#L47)
[removing 'allOf' schema from the response body or response body property](checker/check-response-property-all-of-updated_test.go?plain=1#L47)
[removing 'anyOf' schema from the request body or request body property](checker/check-request-property-any-of-updated_test.go?plain=1#L47)
Expand Down
9 changes: 4 additions & 5 deletions checker/api_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"

"github.com/TwiN/go-color"
"github.com/tufin/oasdiff/checker/localizations"
)

// ApiChange represnts a change in the Paths Section of an OpenAPI spec
Expand Down Expand Up @@ -59,11 +58,11 @@ func (c ApiChange) GetPath() string {
return c.Path
}

func (c ApiChange) LocalizedError(l localizations.Localizer) string {
return fmt.Sprintf("%s %s %s, %s API %s %s %s [%s]. %s", c.Level, l.Get("messages.at"), c.Source, l.Get("messages.in"), c.Operation, c.Path, c.Text, c.Id, c.Comment)
func (c ApiChange) LocalizedError(l Localizer) string {
return fmt.Sprintf("%s %s %s, %s API %s %s %s [%s]. %s", c.Level, l("at"), c.Source, l("in"), c.Operation, c.Path, c.Text, c.Id, c.Comment)
}

func (c ApiChange) PrettyErrorText(l localizations.Localizer) string {
func (c ApiChange) PrettyErrorText(l Localizer) string {
if IsPipedOutput() {
return c.LocalizedError(l)
}
Expand All @@ -72,7 +71,7 @@ func (c ApiChange) PrettyErrorText(l localizations.Localizer) string {
if c.Comment != "" {
comment = fmt.Sprintf("\n\t\t%s", c.Comment)
}
return fmt.Sprintf("%s\t[%s] %s %s\t\n\t%s API %s %s\n\t\t%s%s", c.Level.PrettyString(), color.InYellow(c.Id), l.Get("messages.at"), c.Source, l.Get("messages.in"), color.InGreen(c.Operation), color.InGreen(c.Path), c.Text, comment)
return fmt.Sprintf("%s\t[%s] %s %s\t\n\t%s API %s %s\n\t\t%s%s", c.Level.PrettyString(), color.InYellow(c.Id), l("at"), c.Source, l("in"), color.InGreen(c.Operation), color.InGreen(c.Path), c.Text, comment)
}

func (c ApiChange) Error() string {
Expand Down
6 changes: 2 additions & 4 deletions checker/change.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package checker

import "github.com/tufin/oasdiff/checker/localizations"

type Change interface {
GetId() string
GetText() string
Expand All @@ -12,7 +10,7 @@ type Change interface {
GetPath() string

MatchIgnore(ignorePath, ignoreLine string) bool
LocalizedError(l localizations.Localizer) string
PrettyErrorText(l localizations.Localizer) string
LocalizedError(l Localizer) string
PrettyErrorText(l Localizer) string
Error() string
}
2 changes: 1 addition & 1 deletion checker/check-added-required-request-body.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func AddedRequiredRequestBodyCheck(diffReport *diff.Diff, operationsSources *dif
result = append(result, ApiChange{
Id: "added-required-request-body",
Level: ERR,
Text: config.i18n("added-required-request-body"),
Text: config.Localize("added-required-request-body"),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Expand Down
2 changes: 1 addition & 1 deletion checker/check-api-added.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func APIAddedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSour
result = append(result, ApiChange{
Id: "endpoint-added",
Level: INFO,
Text: config.i18n("endpoint-added"),
Text: config.Localize("endpoint-added"),
Operation: opName,
OperationId: opConfig.OperationID,
Path: path,
Expand Down
8 changes: 4 additions & 4 deletions checker/check-api-deprecation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio
result = append(result, ApiChange{
Id: "endpoint-reactivated",
Level: INFO,
Text: config.i18n("endpoint-reactivated"),
Text: config.Localize("endpoint-reactivated"),
Operation: operation,
OperationId: op.OperationID,
Path: path,
Expand All @@ -45,7 +45,7 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio
result = append(result, ApiChange{
Id: "api-deprecated-sunset-parse",
Level: ERR,
Text: fmt.Sprintf(config.i18n("api-deprecated-sunset-parse"), rawDate, err),
Text: config.Localize("api-deprecated-sunset-parse", rawDate, err),
Operation: operation,
OperationId: op.OperationID,
Path: path,
Expand Down Expand Up @@ -76,7 +76,7 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio
result = append(result, ApiChange{
Id: "api-sunset-date-too-small",
Level: ERR,
Text: fmt.Sprintf(config.i18n("api-sunset-date-too-small"), date, deprecationDays),
Text: config.Localize("api-sunset-date-too-small", date, deprecationDays),
Operation: operation,
OperationId: op.OperationID,
Path: path,
Expand All @@ -89,7 +89,7 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio
result = append(result, ApiChange{
Id: "endpoint-deprecated",
Level: INFO,
Text: config.i18n("endpoint-deprecated"),
Text: config.Localize("endpoint-deprecated"),
Operation: operation,
OperationId: op.OperationID,
Path: path,
Expand Down
6 changes: 2 additions & 4 deletions checker/check-api-operation-id-updated.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package checker

import (
"fmt"

"github.com/tufin/oasdiff/diff"
)

Expand Down Expand Up @@ -33,11 +31,11 @@ func APIOperationIdUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.O

level := INFO
id := apiOperationRemovedCheckId
text := fmt.Sprintf(config.i18n(id), ColorizedValue(operationItem.Base.OperationID), ColorizedValue(operationItem.Revision.OperationID))
text := config.Localize(id, ColorizedValue(operationItem.Base.OperationID), ColorizedValue(operationItem.Revision.OperationID))
if operationItem.OperationIDDiff.From == nil || operationItem.OperationIDDiff.From == "" {
id = apiOperationAddCheckId
op = pathItem.Revision.Operations()[operation]
text = fmt.Sprintf(config.i18n(id), ColorizedValue(operationItem.Revision.OperationID))
text = config.Localize(id, ColorizedValue(operationItem.Revision.OperationID))
}

result = append(result, ApiChange{
Expand Down
13 changes: 6 additions & 7 deletions checker/check-api-removed.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package checker

import (
"fmt"
"time"

"cloud.google.com/go/civil"
Expand All @@ -25,7 +24,7 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo
result = append(result, ApiChange{
Id: "api-path-removed-without-deprecation",
Level: ERR,
Text: config.i18n("api-path-removed-without-deprecation"),
Text: config.Localize("api-path-removed-without-deprecation"),
Operation: operation,
OperationId: op.OperationID,
Path: path,
Expand All @@ -39,7 +38,7 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo
result = append(result, ApiChange{
Id: "api-path-sunset-parse",
Level: ERR,
Text: fmt.Sprintf(config.i18n("api-deprecated-sunset-parse"), rawDate, err),
Text: config.Localize("api-deprecated-sunset-parse", rawDate, err),
Operation: operation,
OperationId: op.OperationID,
Path: path,
Expand All @@ -52,7 +51,7 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo
result = append(result, ApiChange{
Id: "api-path-removed-before-sunset",
Level: ERR,
Text: fmt.Sprintf(config.i18n("api-path-removed-before-sunset"), date),
Text: config.Localize("api-path-removed-before-sunset", date),
Operation: operation,
OperationId: op.OperationID,
Path: path,
Expand All @@ -73,7 +72,7 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo
result = append(result, ApiChange{
Id: "api-removed-without-deprecation",
Level: ERR,
Text: config.i18n("api-removed-without-deprecation"),
Text: config.Localize("api-removed-without-deprecation"),
Operation: operation,
OperationId: op.OperationID,
Path: path,
Expand All @@ -87,7 +86,7 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo
result = append(result, ApiChange{
Id: "api-path-sunset-parse",
Level: ERR,
Text: fmt.Sprintf(config.i18n("api-deprecated-sunset-parse"), rawDate, err),
Text: config.Localize("api-deprecated-sunset-parse", rawDate, err),
Operation: operation,
OperationId: op.OperationID,
Path: path,
Expand All @@ -100,7 +99,7 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo
result = append(result, ApiChange{
Id: "api-removed-before-sunset",
Level: ERR,
Text: fmt.Sprintf(config.i18n("api-removed-before-sunset"), date),
Text: config.Localize("api-removed-before-sunset", date),
Operation: operation,
OperationId: op.OperationID,
Path: path,
Expand Down
Loading

0 comments on commit b9a94b9

Please sign in to comment.