Closed bkeane closed 15 hours ago
The following generated successfully for me:
package design
import . "goa.design/goa/v3/dsl"
var _ = Service("service", func() {
Method("list_resources", func() {
Result(CollectionOf(Resource), func() {
View("some_view")
})
})
})
var Resource = ResultType("application/vnd.goa.resource", "Resource", func() {
Attributes(func() {
Attribute("id", String, "Unique identifier of the resource")
})
View("some_view", func() {
Description("Some useful view")
Attribute("id")
})
})
Would you have a small repro I could try?
Indeed a slightly more complex scenario is at play. I threw a branch up with a repro example here.
EDIT: After pushing this to git, all of a sudden I stopped seeing the issue in my example. So I have yet to get to the bottom of it.
Alright, I had some time to sit down and run through some scenarios. The original error disappeared, at one point reappeared, then quickly disappeared again without any clear causation I've been able to deduce.
However! I am able to recreate what I'm starting to believe is the culprit behind whatever 👻 bug I've been chasing.
It seems that CollectionOf
is not picking up the pathing directive related to Meta("struct:pkg:path", "types")
. Especially in return types.
goa gen github.com/bkeane/gists/design
.gen/as_json/services.go
.// gen/as_json/service.go
// newRow converts projected type Row to service type Row.
func newRow(vres *asjsonviews.RowView) *Row {
res := &types.Row{
ID: vres.ID,
First: vres.First,
Last: vres.Last,
Email: vres.Email,
Ssn: vres.Ssn,
}
return res
}
Internal to this generated function, &types.Row
is correctly referenced, but the return type of *Row
is still assuming Row
to be a part of the top level package design
and not part of the generated types
package.
If you replace CollectionOf
with ArrayOf
the generated code seems fine, but does not involve any response types in this scenario. I do see in a larger codebase this repo structure working with ArrayOf
in more complex scenarios.
Nice, for posterity here is a minimalistic design that reproduces the issue:
package design
import (
. "goa.design/goa/v3/dsl"
)
var _ = Service("AsJson", func() {
Method("index", func() {
Result(CollectionOf(Row))
HTTP(func() { GET("/") })
})
})
var Row = ResultType("application/vnd.goa.row", "Row", func() {
Attributes(func() {
Field(0, "id", String, "Unique identifier a row")
})
Meta("struct:pkg:path", "types")
})
What seems to be the problem?
At least on the http service side of things, there seems to be a problem with generating the likes of...
where
types.Resource
is akin to ...goa gen results in...
Empirical findings.
CollectionOf
, leavingResult(types.Resource, func() { View("some_view") })
, gen runs cleanly.func() { View(...) }
, leavingResult(CollectionOf(types.Resource))
, gen runs cleanly.