goadesign / goa

🌟 Goa: Elevate Go API development! 🚀 Streamlined design, automatic code generation, and seamless HTTP/gRPC support. ✨
https://goa.design
MIT License
5.69k stars 560 forks source link

Unexpected OpenAPI specification when using CollectionOf() + View() in Attribute #3562

Closed neilogic1911 closed 3 months ago

neilogic1911 commented 3 months ago

My API design requirement is to ensure that the elements are included under the data attribute in the response of ListElements:

{
  "pageInfo": {
    // Page information goes here...
  },
  "data": [
    // List of elements goes here...
  ]
}

The Element type have two views: default and tiny. When these views appear in CollectionOf, everything works fine if the tiny collection passed directly to the Result(). However, when the collection is part of an attibute the tiny view will be not work correctly.

demo repo

raphael commented 3 months ago

Thank you for the nice repro. This is fixed by #3567. Note that the explicit view should be defined on the collection, not on the result, i.e.:

        Result(func() {
            Attribute("data", CollectionOf(Element, func() {
                View("tiny")
            }))
        })