-
Notifications
You must be signed in to change notification settings - Fork 59
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
Full init constructor for provided types #91
Comments
According to my knowledge - no, TP SDK does not allow to emit record types fsharp/fslang-suggestions#154 - you may vote for this feature if you like to see it in some future.
SwaggerProvider already provides
I understand you intend, but we still need default parameter-less constructor and property setters to allow serializer ( The only thing we can do is to add one more constructor with enormous number of parameters that initialize all properties. |
Having one empty constructor, and another one that set all the properties of the object would be very helpfull. Any idea when and if you will get around to it? I could give it a try, but i dont have much experience on the coding-side of typeproviders. I would prefer having fields marked with required=false generated as an Option<_>. I see your point, but now you get no distinction if fields are required or not. How about a setting for SwaggerProvider<NonRequiredFieldsAsOptions=true> , or something of the sort :) |
You can try it using v0.10.0-alpha1 and help me test other changes ;) - initial implementation is here 8eb0d88 |
if the property type is a number then you will see difference in types ...
but when the property is What will be the benefit of generating |
Oh great, i'll test it. Thanks and well done :) About the Let's assume you have an Object Pet that has a Required PrimaryCategory of the type PetCategory and another field SecondaryCategory that is optional. With an option type for reference-objects aswell that are optional i just think it gets more intuitive. No option type: {
PetId : int
PrimaryCatergory : PetCategory
SecondayCategory : PetCategory // <-- is it required or not?
} With option type: {
PetId : int
PrimaryCatergory : PetCategory
SecondayCategory : PetCategory option // <-- Optionality explained through type-system
} I agree that its kind of dumb that you can provide Thanks for the constructor-thingy again, And for all the type providers :) |
@sergey-tihon perhaps for the case when the user has requested option types, we can do an Option.ofObj on the deserialized response, to eliminate Some(null) cases and keep the model as pure as possible? |
Description
As it is now Swaggerprovider generates mutable classes for objects. Would it be possible to generate immutable F# records?
Options types for non required fields would also be nice :)
If F# Records are not possible, is it possible to have a default constructor on the generated type that sets all properties of the object? This would minimize risk of not setting an property by accident. And also if the underlying swagger-specification change, and a property is added on the object: You would get a compile-error that you need to set the property.
The text was updated successfully, but these errors were encountered: