generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve ingress schema validation (#1098)
This vastly improves ingress schema validation, ensuring that the request/response body types are valid, and that if path parameters are used the request body is a data structure with a corresponding field. cc @lifeizhou-ap
- Loading branch information
1 parent
6712969
commit 1b15592
Showing
20 changed files
with
391 additions
and
163 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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,41 @@ | ||
package schema | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/alecthomas/assert/v2" | ||
) | ||
|
||
func TestTypeResolver(t *testing.T) { | ||
module, err := ParseModuleString("", ` | ||
module test { | ||
data Request<T> { | ||
t T | ||
} | ||
verb test(Request<String>) Empty | ||
} | ||
`) | ||
assert.NoError(t, err) | ||
scopes := NewScopes() | ||
scopes = scopes.PushScope(module.Scope()) | ||
|
||
// Resolve a builtin. | ||
actualInt, _ := ResolveAs[*Int](scopes, Ref{Name: "Int"}) | ||
assert.NotZero(t, actualInt) | ||
assert.Equal(t, &Int{}, actualInt, assert.Exclude[Position]()) | ||
|
||
// Resolve a generic data structure. | ||
actualData, _ := ResolveAs[*Data](scopes, Ref{Module: "test", Name: "Request"}) | ||
assert.NotZero(t, actualData) | ||
expectedData := &Data{ | ||
Name: "Request", | ||
TypeParameters: []*TypeParameter{{Name: "T"}}, | ||
Fields: []*Field{{Name: "t", Type: &Ref{Name: "T"}}}, | ||
} | ||
assert.Equal(t, expectedData, actualData, assert.Exclude[Position]()) | ||
|
||
// Resolve a type parameter. | ||
scopes = scopes.PushScope(actualData.Scope()) | ||
actualTP, _ := ResolveAs[*TypeParameter](scopes, Ref{Name: "T"}) | ||
assert.Equal(t, actualTP, &TypeParameter{Name: "T"}, assert.Exclude[Position]()) | ||
} |
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
Oops, something went wrong.