Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Default parameter addition check #384

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions checker/check-new-request-non-path-default-parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ func NewRequestNonPathDefaultParameterCheck(diffReport *diff.Diff, operationsSou
continue
}

for paramLoc := range pathItem.ParametersDiff.Added {
for paramLoc, paramNameList := range pathItem.ParametersDiff.Added {
if paramLoc == "path" {
continue
}

for _, param := range pathItem.Revision.Parameters {

if !paramNameList.Contains(param.Value.Name) {
continue
}
id := "new-required-request-default-parameter-to-existing-path"
level := ERR
if !param.Value.Required {
Expand Down
22 changes: 1 addition & 21 deletions checker/check-new-request-non-path-default-parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestNewRequestNonPathParameter_DetectsNewRequiredPathsAndNewOperations(t *t

errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.NewRequestNonPathDefaultParameterCheck), d, osm, checker.INFO)
require.NotEmpty(t, errs)
require.Len(t, errs, 9)
require.Len(t, errs, 7)

require.ElementsMatch(t, []checker.ApiChange{
{
Expand All @@ -44,16 +44,6 @@ func TestNewRequestNonPathParameter_DetectsNewRequiredPathsAndNewOperations(t *t
Path: "/api/test1",
Source: "../data/request_params/required-request-params.yaml",
},
{
Id: "new-required-request-default-parameter-to-existing-path",
Text: "added the new required 'header' request parameter 'id' to all path's operations",
Comment: "",
Level: 3,
Operation: "GET",
OperationId: "getTest",
Path: "/api/test2",
Source: "../data/request_params/required-request-params.yaml",
},
{
Id: "new-required-request-default-parameter-to-existing-path",
Text: "added the new required 'query' request parameter 'id' to all path's operations",
Expand Down Expand Up @@ -103,15 +93,5 @@ func TestNewRequestNonPathParameter_DetectsNewRequiredPathsAndNewOperations(t *t
OperationId: "getTest",
Path: "/api/test2",
Source: "../data/request_params/required-request-params.yaml",
},
{
Id: "new-optional-request-default-parameter-to-existing-path",
Text: "added the new optional 'query' request parameter 'optionalHeaderParam' to all path's operations",
Comment: "",
Level: 1,
Operation: "GET",
OperationId: "getTest",
Path: "/api/test2",
Source: "../data/request_params/required-request-params.yaml",
}}, errs)
}
12 changes: 12 additions & 0 deletions data/request_params/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ info:
openapi: 3.0.3
paths:
/api/test1:
parameters:
- in: query
name: baseQueryParam
required: true
schema:
type: string
get:
operationId: getTest
responses:
Expand All @@ -15,6 +21,12 @@ paths:
description: OK

/api/test2:
parameters:
- in: query
name: baseNotRequiredQueryParam
required: false
schema:
type: string
get:
operationId: getTest
responses:
Expand Down
10 changes: 10 additions & 0 deletions data/request_params/required-request-params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ openapi: 3.0.3
paths:
/api/test1:
parameters:
- in: query
name: baseQueryParam
required: true
schema:
type: string
- in: query
name: version
required: true
Expand Down Expand Up @@ -33,6 +38,11 @@ paths:

/api/test2:
parameters:
- in: query
name: baseNotRequiredQueryParam
required: false
schema:
type: string
- in: query
name: id
required: true
Expand Down