domaindrivendev / Swashbuckle.WebApi

Seamlessly adds a swagger to WebApi projects!
BSD 3-Clause "New" or "Revised" License
3.07k stars 678 forks source link

Max. Value only outputs with `int` Range attributes #792

Open brettveenstra opened 8 years ago

brettveenstra commented 8 years ago

Inside SchemaExtensions, the RangeAttribute handling only supports int values (range.OperandType == typeof(int)) so have to use int for all Range declarations which is limiting.

Tried to implement a fix but Schema class is also using maximum and minimum for Enum listing so modifying the type for those fields is not straightforward ... perhaps one of the following:

Can you advise a workaround or how to separate handling of the Enum and RangeAttributes?

domaindrivendev commented 8 years ago

That's a good catch and honestly I can't remember why I restricted to integer's. It seems like the maximum and minimum fields on the Schema class could be changed - "object" seems to be the most appropriate type.

However, I'm not understanding your point around enum's. I can't see where maximum / minimum are being used for enum's. I think the two are mutually exclusive.

It's also worth noting that right now, I'm putting most of my energy into the next generation of SB (6.0.0) that targets AspNet Core. I'll definitely get this fixed for that version. I do plan on making one or two more releases for the 5.x line, addressing critical fixes / feature requests, but I'm not sure if this fits that bill. Perhaps a PR (with tests included) would help :)

brettveenstra commented 8 years ago

I think the Enum listing I was referring to was: https://github.com/domaindrivendev/Swashbuckle/blob/fd2a7e9e9f01a3fa1ad4403c5a5d4b6f5c54f0b4/Swashbuckle.Tests/Swagger/SchemaTests.cs#L55

or perhaps: https://github.com/domaindrivendev/Swashbuckle/blob/953f9803bdf4a5051dd4ad90f8a6bc0ad8b6af3b/Swashbuckle.Tests/Swagger/CoreTests.cs#L527

I'll have to find my edits again for more specifics. As I remember, it wasn't until I tried to work it out in the existing tests that the Enum problem occurred and I was confused how to proceed.

jasonchester commented 6 years ago

Will this add support for setting min/max values for parameters of long type as well.

/* snip */
if (swaggerParam is NonBodyParameter)
{
    ((NonBodyParameter)swaggerParam).Minimum = long.MinValue;
    ((NonBodyParameter)swaggerParam).Maximum = long.MaxValue;
}
/* snip */