-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parser: catch API endpoints being referenced but not called
The refactoring in preparation for cron jobs accidentally made the parser more permissive about referencing endpoints. Make it more precise by allowing this in certain places but not others. Fixes #142
- Loading branch information
Showing
9 changed files
with
161 additions
and
67 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,53 @@ | ||
build | ||
|
||
-- go.mod -- | ||
module test | ||
|
||
require "encore.dev" v0.0.0 | ||
|
||
-- one/one.go -- | ||
package one | ||
|
||
import ( | ||
"context" | ||
|
||
"test/one/nested" | ||
) | ||
|
||
type OneResponse struct { | ||
Message string | ||
} | ||
|
||
//encore:api public | ||
func One(ctx context.Context) (*OneResponse, error) { | ||
if err := nested.One(ctx); err != nil { | ||
return nil, err | ||
} | ||
return &OneResponse{Message: "Hello, World!"}, nil | ||
} | ||
|
||
-- one/nested/nested.go -- | ||
package nested | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
func One(ctx context.Context) error { | ||
return nil | ||
} | ||
|
||
-- two/two.go -- | ||
package two | ||
|
||
import ( | ||
"context" | ||
|
||
"test/one" | ||
) | ||
|
||
//encore:api public | ||
func Two(ctx context.Context) error { | ||
_, err := one.One(ctx) | ||
return err | ||
} |
File renamed without changes.
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,27 @@ | ||
! parse | ||
stderr 'cannot reference API one.One outside of a service' | ||
|
||
-- one/one.go -- | ||
package one | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
//encore:api public | ||
func One(ctx context.Context) error { | ||
return nil | ||
} | ||
|
||
-- two/two.go -- | ||
package two | ||
|
||
import ( | ||
"context" | ||
|
||
"test/one" | ||
) | ||
|
||
func Foo(ctx context.Context) error { | ||
return one.One(ctx) | ||
} |
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,31 @@ | ||
# Verify that not calling an endpoint is caught by the parser | ||
! parse | ||
stderr 'cannot reference API endpoint one.One without calling it' | ||
|
||
-- one/one.go -- | ||
package one | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
//encore:api public | ||
func One(ctx context.Context) error { | ||
return nil | ||
} | ||
|
||
-- two/two.go -- | ||
package two | ||
|
||
import ( | ||
"context" | ||
|
||
"test/one" | ||
) | ||
|
||
//encore:api public | ||
func Foo(ctx context.Context) error { | ||
f := one.One | ||
f() | ||
return nil | ||
} |