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

Specify a custom Content-Type for Goa errors and MediaTypes, Types #694

Closed
dobegor opened this issue Aug 5, 2016 · 2 comments
Closed

Specify a custom Content-Type for Goa errors and MediaTypes, Types #694

dobegor opened this issue Aug 5, 2016 · 2 comments
Labels

Comments

@dobegor
Copy link
Contributor

dobegor commented Aug 5, 2016

Goa should provide a way to specify custom Content-Type instead of forcing RFC 6848. There are applications which don't respect that (i.e., swagger-codegen is producing Java client which fails to decode response).

Currently there is no way to do that.

@raphael
Copy link
Member

raphael commented Aug 5, 2016

It's possible today by using the ContentType function in the design:

var BottleMedia = MediaType("application/vnd.foo", func() {
    ContentType("application/json")
    // ...
}

@raphael raphael closed this as completed Aug 5, 2016
@raphael raphael reopened this Aug 5, 2016
@raphael raphael added the bug label Aug 5, 2016
@dobegor
Copy link
Contributor Author

dobegor commented Aug 7, 2016

Here is an example:

package design

import (
    . "github.com/goadesign/goa/design"
    . "github.com/goadesign/goa/design/apidsl"
)

var _ = API("test", func() {
    Title("test api")
    Scheme("http")
    Host("localhost:8080")
})

var Greeting = MediaType("application/vnd.greeting+json", func() {
    ContentType("application/json")
    Attributes(func() {
        Attribute("greeting", String, "greeting text")
    })

    View("default", func() {
        Attribute("greeting")
    })
})

var _ = Resource("hello", func() {
    BasePath("/hello")
    Action("hello", func() {
        Routing(GET("/"))
        Response(OK, Greeting)
    })
})

Controller:

// Hello runs the hello action.
func (c *HelloController) Hello(ctx *app.HelloHelloContext) error {
    // HelloController_Hello: start_implement

    // Put your logic here

    // HelloController_Hello: end_implement
    s := "hello world"
    res := &app.Greeting{
        Greeting: &s,
    }
    return ctx.OK(res)
}

Result:
2016-08-07-195759_917x714_scrot

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

No branches or pull requests

2 participants