Skip to content

Commit

Permalink
Fix: Default parameter addition check (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan-Rosenberg authored Sep 19, 2023
1 parent 34d3dbf commit bdb2a75
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
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

0 comments on commit bdb2a75

Please sign in to comment.