Skip to content
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

bug: Using no relative path prefix produces wrong code dsl.Files #3663

Open
gabyx opened this issue Mar 4, 2025 · 2 comments
Open

bug: Using no relative path prefix produces wrong code dsl.Files #3663

gabyx opened this issue Mar 4, 2025 · 2 comments

Comments

@gabyx
Copy link

gabyx commented Mar 4, 2025

Goa is awesome, but we have seen an issue which occures when doing:

	dsl.Files("/mysuperduperapi.json", "a/b/c/openapi3.json")

The code does produces ([code])(https://github.com/goadesign/examples/blob/master/basic/gen/http/calc/server/server.go#L56)

	fileSystemPkgGenHTTPOpenapi3JSON = appendPrefix(fileSystemPkgGenHTTPOpenapi3JSON, "/a/b/c")

but if the a/b/c/ is dropped, e.g. dsl.Files("/mysuperduperapi.json", "openapi3.json")

Goa does not generate the appendPrefix which does not result in selecting the openapi3.json but trying to access mysuperduperapi.json.
So I think appendPrefix should always be generate even if its with "." to select the openapi3.json.

P.S. Maybe this is also intended behavior, but its kind of odd, because only

  • dsl.Files("/openapi3.json", "openapi3.json") works
  • dsl.Files("/openapi.json", "openapi3.json") does not work

This is triggered by this line basically

@gabyx
Copy link
Author

gabyx commented Mar 4, 2025

IMO: Changing

{{- if ne $prefix "/" }}
	{{ .ArgName }} = appendPrefix({{ .ArgName }}, "{{ $prefix }}")
{{- end }}

to

	{{ .ArgName }} = appendPrefix({{ .ArgName }}, "{{ $prefix }}")

should always work as the s.fs.Open(path.Join("/", name) in appendFS is not harmful.

@raphael
Copy link
Member

raphael commented Mar 9, 2025

Wouldn't making this change cause a different behavior when serving files from the filesystem? the path /foo isn't equivalent to foo, the Files comment documents the difference (absolute vs. relative paths).

I don't quite follow:

Goa does not generate the appendPrefix which does not result in selecting the openapi3.json but trying to access mysuperduperapi.json.

Goa should serve openapi3.json using a relative path (that is the file should live in the current directory of the service process). If Goa really attempts to serve mysuperduperapi.json then that's a bug.

Would you be able to provide a complete minimal design that reproduces the issue? that would probably help, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants