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

Required properties #219

Closed
jkonecki opened this issue Jul 16, 2015 · 1 comment
Closed

Required properties #219

jkonecki opened this issue Jul 16, 2015 · 1 comment

Comments

@jkonecki
Copy link
Contributor

C# generator creates all primitive type properties as Nullable<T>. If the property is declared as required in swagger.json should we generate property of type T instead of Nullable<T>?

The required flag is already captured and PrimaryType could be easily extended to support nullability explicitly - SwaggerObject.ToType() method could just use already present IsReguired property.

A config option can be added to turn this behaviour on/off if backwards compatibility is required.

I'm happy to create a PR - just wondering if there are any side-effects I'm not aware of.

@hovsepm
Copy link
Contributor

hovsepm commented Jul 16, 2015

@jkonecki, this was done on purpose. Having nullable primitive types everywhere simplifies logic for PATCH like operations and null validation. Additionally having primitive types in the response insures that deserialization does not throw when the data is missing on the wire (e.g. server changed the field to be nullable but the client was not regenerated with the latest swagger spec).

We still have a validation before serialization for the required fields inside generated methods during runtime.

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