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

Decimal could be added as a format. The sequel of the issue #253 #255

Closed
alexkostyanikov opened this issue Mar 26, 2015 · 3 comments
Closed

Decimal could be added as a format. The sequel of the issue #253 #255

alexkostyanikov opened this issue Mar 26, 2015 · 3 comments

Comments

@alexkostyanikov
Copy link

@alexkostyanikov alexkostyanikov commented Mar 26, 2015

Hi once again
I have discussed about the issue #253 with swagger-spec guys. Could you have a look?
OAI/OpenAPI-Specification#316

The main point is
"The spec does allow you to use whichever format you want, so if you want to call it float128bit or decimal, you can. It doesn't mean the tools will be able to parse it automatically though. As for the type, it's definitely number in this case."

It is described in https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#data-types, third paragraph.

Could you do this?

@domaindrivendev

This comment has been minimized.

Copy link
Owner

@domaindrivendev domaindrivendev commented Mar 26, 2015

Thanks for digging deeper and getting this additional info from the Swagger folks. I'm on the fence about adding an unknown format, particularly if there's a chance it could degrade any existing tools out there just to satisfy one specific client generator for .Net. I would need to think about it a bit more.

In the meantime, it's worth noting you can override the mapping for System.Decimal very easily on the server-side with the following config setting (see readme for more info)

config.MapType<decimal>(() => new Schema { type="number", format="decimal" });

On the client-side, this may not help much, but you could use double by default and provide a howto on getting decimal support into a WebApi. In fact, server-side changes will be required to even make the WebApi JSON serializer handle doubles differently to decimals in the first place.

@alexkostyanikov

This comment has been minimized.

Copy link
Author

@alexkostyanikov alexkostyanikov commented Mar 26, 2015

oh. it is very useful advise.
thanx

Another point that i had regards to nullable values. Is it the same solution? we can override mapping for this?
config.MapType<int?>(() => new Schema { type="number", format="int?" });

or there is another cause that you don't support them?

@domaindrivendev

This comment has been minimized.

Copy link
Owner

@domaindrivendev domaindrivendev commented Apr 2, 2015

"decimal", "int?" etc. are all formats which would be quite specific to the .NET stack. Swagger isn't about describing a .NET API - it's about describing a REST/HTTP-based API independent of the platform that the service happens to be built on.

At this level of abstraction a nullable type would be represented as a "non-required", "primitive" JSON schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.