generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
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: skip validation on external req/resp types #1304
Merged
+30
−13
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,7 +264,7 @@ func ValidateModule(module *Module) error { | |
merr = append(merr, errorf(n, "Verb name %q is a reserved word", n.Name)) | ||
} | ||
|
||
merr = append(merr, validateVerbMetadata(scopes, n)...) | ||
merr = append(merr, validateVerbMetadata(scopes, module, n)...) | ||
|
||
case *Data: | ||
if !ValidateName(n.Name) { | ||
|
@@ -443,7 +443,7 @@ func errorf(pos interface{ Position() Position }, format string, args ...interfa | |
return Errorf(pos.Position(), pos.Position().Column, format, args...) | ||
} | ||
|
||
func validateVerbMetadata(scopes Scopes, n *Verb) (merr []error) { | ||
func validateVerbMetadata(scopes Scopes, module *Module, n *Verb) (merr []error) { | ||
// Validate metadata | ||
metadataTypes := map[reflect.Type]bool{} | ||
for _, md := range n.Metadata { | ||
|
@@ -456,9 +456,9 @@ func validateVerbMetadata(scopes Scopes, n *Verb) (merr []error) { | |
|
||
switch md := md.(type) { | ||
case *MetadataIngress: | ||
reqBodyType, reqBody, errs := validateIngressRequestOrResponse(scopes, n, "request", n.Request) | ||
reqBodyType, reqBody, errs := validateIngressRequestOrResponse(scopes, module, n, "request", n.Request) | ||
merr = append(merr, errs...) | ||
_, _, errs = validateIngressRequestOrResponse(scopes, n, "response", n.Response) | ||
_, _, errs = validateIngressRequestOrResponse(scopes, module, n, "response", n.Response) | ||
merr = append(merr, errs...) | ||
|
||
// Validate path | ||
|
@@ -492,11 +492,11 @@ func validateVerbMetadata(scopes Scopes, n *Verb) (merr []error) { | |
return | ||
} | ||
|
||
func validateIngressRequestOrResponse(scopes Scopes, n *Verb, reqOrResp string, r Type) (fieldType Type, body Symbol, merr []error) { | ||
func validateIngressRequestOrResponse(scopes Scopes, module *Module, n *Verb, reqOrResp string, r Type) (fieldType Type, body Symbol, merr []error) { | ||
rref, _ := r.(*Ref) | ||
resp, sym := ResolveTypeAs[*Data](scopes, r) | ||
module, _ := sym.Module.Get() | ||
if sym == nil || module == nil || module.Name != "builtin" || resp.Name != "Http"+strings.Title(reqOrResp) { | ||
m, _ := sym.Module.Get() | ||
if sym == nil || m == nil || m.Name != "builtin" || resp.Name != "Http"+strings.Title(reqOrResp) { | ||
merr = append(merr, errorf(r, "ingress verb %s: %s type %s must be builtin.HttpRequest", n.Name, reqOrResp, r)) | ||
return | ||
} | ||
|
@@ -512,9 +512,16 @@ func validateIngressRequestOrResponse(scopes Scopes, n *Verb, reqOrResp string, | |
if opt, ok := fieldType.(*Optional); ok { | ||
fieldType = opt.Type | ||
} | ||
|
||
if ref, err := ParseRef(fieldType.String()); err == nil { | ||
if ref.Module != "" && ref.Module != module.Name { | ||
return // ignores references to other modules. | ||
} | ||
} | ||
|
||
bodySym := scopes.ResolveType(fieldType) | ||
if bodySym == nil { | ||
merr = append(merr, errorf(resp, "ingress verb %s: couldn't resolve %s body type %s", n.Name, reqOrResp, fieldType)) | ||
merr = append(merr, errorf(r, "ingress verb %s: couldn't resolve %s body type %s", n.Name, reqOrResp, fieldType)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes the issue where |
||
return | ||
} | ||
body = bodySym.Symbol | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces logic to not validate resp body types for external modules since we don't have the full schema here, just a single module. This follows the comments for
ValidateModule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this get validated in
ValidateSchema
instead now? I don't see that in this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I believe that code is here:
https://github.com/TBD54566975/ftl/blob/main/backend/schema/validate.go#L137
and tested here:
https://github.com/TBD54566975/ftl/blob/main/backend/schema/schema_test.go#L211-L214