No validation error for additional fields in request payload using goa

84 views Asked by At

current situation

for our service we have the current working implementation (same behaviour for all other endpoints):

var _ = goa.Service("serviceDemo", func() { 
    goa.Method("secondEndpoint", func() {
        goa.Payload(SecondEndpointRequestPayload)
        goa.Result(SecondEndpointResponsePayload)
        goa.HTTP(func() {
            goa.Headers(func() {
                goa.Header("first-header", goa.String)
                goa.Header("second-header", goa.String)
            })
            goa.POST("secondEndpoint")
            goa.Response(func() {
                goa.Code(goa.StatusOK)
                goa.ContentType(HTTPContentTypeApplicationJSONCharsetUTF8)
            })
        })
    })

    goa.Error(ErrorNameUnexpected, UnexpectedErrorResponsePayload)
    goa.Error(ErrorNameInvalidPayload, InvalidPayloadErrorResponsePayload)
    goa.Error(ErrorNameNotFound, NotFoundErrorResponsePayload)
    goa.Error(ErrorNameForbidden, ForbiddenErrorResponsePayload)
    goa.HTTP(func() {
        goa.Path("/v1/serviceDemo")
        goa.Response(ErrorNameUnexpected, func() {
            goa.Code(goa.StatusInternalServerError)
            goa.ContentType(HTTPContentTypeApplicationJSONCharsetUTF8)
        })
        goa.Response(ErrorNameInvalidPayload, func() {
            goa.Code(goa.StatusBadRequest)
            goa.ContentType(HTTPContentTypeApplicationJSONCharsetUTF8)
        })
        goa.Response(ErrorNameNotFound, func() {
            goa.Code(goa.StatusNotFound)
            goa.ContentType(HTTPContentTypeApplicationJSONCharsetUTF8)
        })
        goa.Response(ErrorNameForbidden, func() {
            goa.Code(goa.StatusForbidden)
            goa.ContentType(HTTPContentTypeApplicationJSONCharsetUTF8)
        })
    })
})
...
var SecondEndpointRequestPayload = goa.Type("SecondEndpointRequestPayload", func() {
    goa.TypeName("SecondEndpointRequestPayload")

    goa.Attribute("first-header", goa.String)
    goa.Attribute("second-header", goa.String)

    goa.Attribute("field1", goa.String)

    goa.Required(
        "field1",
    )
})

Expected

validation error when sending payload with extra field Example:

{
"field1": "value1",
"field2": "value2"
}

received:

200 statusCode and only field1 is passed to the service implementation

Note: i went through goa documentation i can not find how to add validation to forbid additionnal fields , as far as i understood they don't get mapped at all.

0

There are 0 answers