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

Impossible to add headers in response #343

Closed
dejanberic opened this issue May 20, 2015 · 2 comments
Closed

Impossible to add headers in response #343

dejanberic opened this issue May 20, 2015 · 2 comments
Milestone

Comments

@dejanberic
Copy link

Class response looks like this:

    public class Response
    {
        public string description;

        public Schema schema;

        public IList<Header> headers;

        public object examples;
    }

When this is serialized to json it does not comply with Swagger spec 2.0.

As per swagger 2.0, https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md

Response with headers:

{
"description": "A simple string response",
"schema": {
"type": "string"
},
"headers": {
"X-Rate-Limit-Limit": {
"description": "The number of allowed requests in the current period",
"type": "integer"
},
"X-Rate-Limit-Remaining": {
"description": "The number of remaining requests in the current period",
"type": "integer"
},
"X-Rate-Limit-Reset": {
"description": "The number of seconds left in the current period",
"type": "integer"
}
}
}

Notice that headers is not an array but an object which consists of several objects.

One way of solving this is to remove headers property from this class and introduce vendorExtensions property. So I could do something like this:

    public class BaseHeaders
    {
        [JsonProperty("X-Rate-Limit-Limit")]
        public Header XRateLimitLimit { get; set; }

        [JsonProperty("X-Rate-Limit-Remaining")]
        public Header XRateLimitRemaining { get; set; }

        [JsonProperty("X-Rate-Limit-Reset")]
        public Header XRateLimitReset { get; set; }
    }

    BaseHeaders headers = new BaseHeaders();
                headers.XRateLimitLimit = new Header()
                {
                    description = "Maximum number of requests permitted per minute",
                    type = "integer"
                };

                headers.XRateLimitRemaining = new Header()
                {
                    description = "Remaining number of requests",
                    type = "integer"
                };

                headers.XRateLimitReset = new Header()
                {
                    description = "Time in epoch seconds when limit will be reset",
                    type = "integer"
                };
    response.vendorExtensions.Add("headers", headers);

Now this is really ugly solution but it would be nice if headers could be a dictionary type.

@domaindrivendev
Copy link
Owner

Yep this is def a bug in SB. I Think at one point, when the spec was in flux, this used to be Json array.

Will update to dictionary for next release

Thanks for pointing this out

@domaindrivendev
Copy link
Owner

Should be resolved in latest release - 5.2.0

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

No branches or pull requests

2 participants