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

Cannot require multiple headers in separate Trait or Headers definitions #1258

Closed
AmandaLou opened this issue Jun 9, 2017 · 1 comment
Closed
Labels

Comments

@AmandaLou
Copy link

If I define two separate traits, each with a required header, such as:

Trait("version_required”, func() {
    Headers(func() {
        Header("X-Api-Version", String,
            "API Version, must be specified",
            func() { Enum("2017-05-21", "latest") })
        Required("X-Api-Version")
    })
})
Trait("etag_required", func() {
    Headers(func() {
        Header("Etag", UUID,
            "ETag is part of http standard, and is used for detecting resource conflicts")
        Required("Etag")

        })
    })

Then use them both on an action,

Action("show", func() {
    UseTrait("version_required", "etag_required")
    Routing(
        GET(…

Only the one mentioned first("version_required” in this case) will be required. The subsequent ones will be validated for data type if sent, but not required.

The same is true for headers added directly to the action.

Action("show", func() {
    UseTrait("etag_required")
    Headers(func() {
        Header("X-Api-Version", String,
            "API Version, must be specified either using this header or a query string param",
            func() { Enum("2017-05-21", "latest") })
        Required("X-Api-Version")
    })
    Routing(
        GET(…

Etag will be required, but X-Api-Version will not be.

If I require all headers in the same Trait or Headers definition, it does work as expected and requires them all.

@raphael raphael added the bug label Jun 10, 2017
@raphael
Copy link
Member

raphael commented Jun 10, 2017

Thank you for the detailed report, it's indeed a bug.

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