-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add required field to generated ToSchema instances #137
base: master
Are you sure you want to change the base?
Conversation
I'm now going to point my version of |
I found doctests in |
@rashadg1030: Yeah, I saw that. Is it possibly related to the fact that you still have some places in the code that use |
@Gabriel439 Thank you, yes it is related. I think I see what the problem is now. The reason I still use the |
Assigning to @lambdadog to review so that we get a fresh pair of eyes on this |
This reverts commit 52a8b88.
The single line added should make fields that are enum types required. Enum types are named prim types.
@lambdadog The most recent changes I've made to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doctest has been fixed
Okay so after seeing the
The second pattern match matches on Here's my solution to fix the problem: Change
to ->:
This way we can pattern match better and affect Edit: Wait nevermind I think I can match on the Edit2: My first edit is wrong. |
I think it's a good idea to add a test or two for testing the output of |
@rashadg1030: I think it should be possible to pattern match on just |
@rashadg1030: Also, you might not need to make enums required anyway |
Okay I think I know what I need to do. I need to lookup up the field in the
This should allow me to distinguish between |
generates this datatype:
Does this mean this should be?:
|
@rashadg1030 and I pair-programmed on this and concluded that we might be able to correctly mark enums as required. One of the relevant functions we'll have to change, though, is this one: proto3-suite/src/Proto3/Suite/DotProto/Internal.hs Lines 287 to 309 in 185517b
… since it's currently ignoring enums completely when processing definitions. |
We believe that
The issue I think is that Edit: Actually I think the second pattern match of |
Going to briefly explain the changes I made yesterday here, but before I do I'd like to share this interesting thought which can be found in this comment: https://github.com/awakesecurity-dev/end-to-end/pull/13866#issuecomment-673656038
|
With that being said, the motivation for the most recent changes were this:
|
-> [String] | ||
-- ^ Field names | ||
-> [(String, Bool)] | ||
-- ^ Field and if it is nested oneof field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should be fixed. The field represents whether a field is required or not
Okay so this is were I realized that adding enum fields to the type context is troublesome:
There is no way to specifically grab a field that is an enum. Once again the only solution I see to this is doing this:
but as @Gabriel439 said this is an invasive change and doesn't follow the |
@rashadg1030: Yeah, there is always the option of not making enums required at all. I think this route is only worth exploring if it's easy, but if it's not then we can go with the simpler approach of not requiring enums |
@Gabriel439 @natefaubion I'm going ahead with making
will generate the following schema:
which would generate this PureScript code:
|
Currently in our UI these are all considered required. If we do that, we will need to maintain special cases in the UI codegen. I do not want to introduce partiality for every enum for data that we get from the API. Most of our use cases our consuming data from the API, and this is just going to be saying that they may not be there (yet they are), and we will have to pervasively handle that case otherwise. I do not think this is the correct decision for our UI code, but since we already maintain special cases, we will just continue to do so. |
@natefaubion Yes, I would also like the frontend developers to get the easiest data to work with. You shouldn't have to maintain those special cases. Making |
This is my second attempt to have the required fields specified in the generated
swagger.json
file.