Skip to content

Commit

Permalink
add check descriptions phase 1 (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven Harrison authored Nov 8, 2023
1 parent dfad554 commit 909d77e
Show file tree
Hide file tree
Showing 28 changed files with 382 additions and 321 deletions.
2 changes: 1 addition & 1 deletion checker/check-api-operation-id-updated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestOperationIdAdded(t *testing.T) {
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIOperationIdUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "api-operation-id-added",
Id: checker.APIOperationIdAddId,
Text: "api operation id 'NewOperationId' was added",
Comment: "",
Level: checker.INFO,
Expand Down
16 changes: 8 additions & 8 deletions checker/check-api-security-updated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAPIGlobalSecurityyAdded(t *testing.T) {
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.SecurityChange{
Id: "api-global-security-added",
Id: checker.APIGlobalSecurityAddedCheckId,
Text: "the security scheme 'petstore_auth' was added to the API",
Comment: "",
Level: checker.INFO,
Expand All @@ -40,7 +40,7 @@ func TestAPIGlobalSecurityyDeleted(t *testing.T) {
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.SecurityChange{
Id: "api-global-security-removed",
Id: checker.APIGlobalSecurityRemovedCheckId,
Text: "the security scheme 'petstore_auth' was removed from the API",
Comment: "",
Level: checker.INFO,
Expand All @@ -61,7 +61,7 @@ func TestAPIGlobalSecurityScopeRemoved(t *testing.T) {
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.SecurityChange{
Id: "api-global-security-scope-removed",
Id: checker.APIGlobalSecurityScopeRemovedId,
Text: "the security scope 'read:pets' was removed from the global security scheme 'petstore_auth'",
Comment: "",
Level: checker.INFO,
Expand All @@ -82,7 +82,7 @@ func TestAPIGlobalSecurityScopeAdded(t *testing.T) {
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.SecurityChange{
Id: "api-global-security-scope-added",
Id: checker.APIGlobalSecurityScopeAddedId,
Text: "the security scope 'read:pets' was added to the global security scheme 'petstore_auth'",
Comment: "",
Level: checker.INFO,
Expand All @@ -102,7 +102,7 @@ func TestAPISecurityAdded(t *testing.T) {
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "api-security-added",
Id: checker.APISecurityAddedCheckId,
Text: "the endpoint scheme security 'petstore_auth' was added to the API",
Comment: "",
Level: checker.INFO,
Expand All @@ -125,7 +125,7 @@ func TestAPISecurityDeleted(t *testing.T) {
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "api-security-removed",
Id: checker.APISecurityRemovedCheckId,
Text: "the endpoint scheme security 'petstore_auth' was removed from the API",
Comment: "",
Level: checker.INFO,
Expand All @@ -148,7 +148,7 @@ func TestAPISecurityScopeRemoved(t *testing.T) {
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "api-security-scope-removed",
Id: checker.APISecurityScopeRemovedId,
Text: "the security scope 'read:pets' was removed from the endpoint's security scheme 'petstore_auth'",
Comment: "",
Level: checker.INFO,
Expand All @@ -171,7 +171,7 @@ func TestAPISecurityScopeAdded(t *testing.T) {
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "api-security-scope-added",
Id: checker.APISecurityScopeAddedId,
Text: "the security scope 'read:pets' was added to the endpoint's security scheme 'petstore_auth'",
Comment: "",
Level: checker.INFO,
Expand Down
2 changes: 1 addition & 1 deletion checker/checker_breaking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func getConfig() *diff.Config {
func TestBreaking_DeletedPath(t *testing.T) {
errs := d(t, getConfig(), 1, 701)
require.Len(t, errs, 1)
require.Equal(t, "api-path-removed-without-deprecation", errs[0].GetId())
require.Equal(t, checker.APIPathRemovedWithoutDeprecationId, errs[0].GetId())
}

// BC: deleting an operation is breaking
Expand Down
2 changes: 1 addition & 1 deletion checker/checker_deprecation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func singleCheckConfig(c checker.BackwardCompatibilityCheck) checker.Config {
Checks: []checker.BackwardCompatibilityCheck{c},
MinSunsetBetaDays: 31,
MinSunsetStableDays: 180,
Localize: checker.NewLocalizer("en", "en"),
Localize: checker.NewDefaultLocalizer(),
}
}

Expand Down
19 changes: 15 additions & 4 deletions checker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@ import (

type Localizer func(key string, args ...interface{}) string

func NewLocalizer(locale string, fallbackLocale string) Localizer {
locales := localizations.New(locale, fallbackLocale)
func NewDefaultLocalizer() Localizer {
return NewLocalizer(localizations.LangDefault)
}

func NewLocalizer(locale string) Localizer {
locales := localizations.New(locale, localizations.LangDefault)

return func(originalKey string, args ...interface{}) string {
key := "messages." + originalKey
pattern := locales.Get(key)

return func(key string, args ...interface{}) string {
pattern := locales.Get("messages." + key)
// if key not found, return original key
// TODO: improve localizations to return error when key not found
if pattern == key {
return originalKey
}

return fmt.Sprintf(pattern, args...)
}
Expand Down
6 changes: 3 additions & 3 deletions checker/default_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func getBackwardCompatibilityCheckConfig(checks []BackwardCompatibilityCheck, le
LogLevelOverrides: levelOverrides,
MinSunsetBetaDays: minSunsetBetaDays,
MinSunsetStableDays: minSunsetStableDays,
Localize: NewLocalizer("en", "en"),
Localize: NewDefaultLocalizer(),
}
}

func optionalChecks() map[string]BackwardCompatibilityCheck {
optionalRules := GetOptionalRules()
optionalRules := GetOptionalRules(NewDefaultLocalizer())

result := make(map[string]BackwardCompatibilityCheck, len(optionalRules))
for _, rule := range optionalRules {
Expand All @@ -66,7 +66,7 @@ func defaultChecks() []BackwardCompatibilityCheck {

result := []BackwardCompatibilityCheck{}
m := utils.StringSet{}
for _, rule := range GetRequiredRules() {
for _, rule := range GetRequiredRules(NewDefaultLocalizer()) {
pStr := fmt.Sprintf("%v", rule.Handler)
if !m.Contains(pStr) {
m.Add(pStr)
Expand Down
2 changes: 1 addition & 1 deletion checker/deprecation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func getSunsetDate(Extensions map[string]interface{}) (string, civil.Date, error
if !ok {
sunsetJson, ok := Extensions[diff.SunsetExtension].(json.RawMessage)
if !ok {
return "", civil.Date{}, errors.New("sunset header not found")
return "", civil.Date{}, errors.New("sunset extension not found")
}
if err := json.Unmarshal(sunsetJson, &sunset); err != nil {
return "", civil.Date{}, errors.New("unmarshal failed")
Expand Down
11 changes: 11 additions & 0 deletions checker/localizations/lang.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package localizations

const (
LangDefault = LangEn
LangEn = "en"
LangRu = "ru"
)

func GetSupportedLanguages() []string {
return []string{LangEn, LangRu}
}
13 changes: 12 additions & 1 deletion checker/localizations/localizations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions checker/localizations_src/en/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,14 @@ request-required-property-became-write-only: the request required property %s be
request-required-property-became-not-write-only: the request required property %s became not write-only
new-required-request-default-parameter-to-existing-path: added the new required %s request parameter %s to all path's operations
new-optional-request-default-parameter-to-existing-path: added the new optional %s request parameter %s to all path's operations
added-required-request-body-description: a new required request body was added
api-deprecated-sunset-parse-description: invalid or missing sunset extension
endpoint-added-description: a new endpoint was added
api-global-security-added-description: a new security scheme was added under security
api-global-security-removed-description: a security scheme was deleted under security
api-global-security-scope-added-description: a new scope was added to a security scheme under security
api-global-security-scope-removed-description: a scope was deleted from a security scheme under security
api-operation-id-added-description: an operation ID was added to an endpoint
api-operation-id-removed-description: an operation ID was deleted from an endpoint
api-path-removed-before-sunset-description: an endpoint was deleted before sunset date
api-path-removed-without-deprecation-description: an endpoint was deleted without deprecation
Loading

0 comments on commit 909d77e

Please sign in to comment.