-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openapi3: add a test for additionalProperties: false validation (#975)
* test: add a test for additionalProperties: false validation * goimports
- Loading branch information
1 parent
0ed9f5d
commit 4b53bf6
Showing
1 changed file
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package openapi3 | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIssue82(t *testing.T) { | ||
payload := map[string]interface{}{ | ||
"prop1": "val", | ||
"prop3": "val", | ||
} | ||
|
||
schemas := []string{` | ||
{ | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["prop1"], | ||
"properties": { | ||
"prop1": { | ||
"type": "string" | ||
} | ||
} | ||
}`, `{ | ||
"anyOf": [ | ||
{ | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["prop1"], | ||
"properties": { | ||
"prop1": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"prop2": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
] | ||
}`, `{ | ||
"oneOf": [ | ||
{ | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["prop1"], | ||
"properties": { | ||
"prop1": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"prop2": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
] | ||
}`, `{ | ||
"allOf": [ | ||
{ | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["prop1"], | ||
"properties": { | ||
"prop1": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"prop2": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
`} | ||
|
||
for _, jsonSchema := range schemas { | ||
var dataSchema Schema | ||
err := json.Unmarshal([]byte(jsonSchema), &dataSchema) | ||
require.NoError(t, err) | ||
|
||
err = dataSchema.VisitJSON(payload) | ||
require.Error(t, err) | ||
} | ||
} |