Support for Specification Extensions #11 for v3.2.2 (with aeson 2 support)#43
Support for Specification Extensions #11 for v3.2.2 (with aeson 2 support)#43alexbiehl wants to merge 9 commits intobiocad:masterfrom
Conversation
|
Wonderful! Now tests pass. I will take a look at the code shortly, thanks! |
| -- the examples value SHALL override the example provided by the schema. | ||
| , _paramExamples :: InsOrdHashMap Text (Referenced Example) | ||
|
|
||
| , _paramExtensions :: SpecificationExtensions |
| makeFields ''Example | ||
| makeFields ''Discriminator | ||
| makeFields ''Link | ||
| makeLenses ''SpecificationExtensions |
There was a problem hiding this comment.
I believe corresponding changes should be done to Optics.hs as well?
| @@ -0,0 +1,47 @@ | |||
| # This file was autogenerated by Stack. | |||
There was a problem hiding this comment.
Does this need to be in the repo? I'm not even sure if current stack.yaml works at all, I use only cabal...
There was a problem hiding this comment.
I usually just use cabal too nowadays, but if there's a stack.yaml I'll usually use stack.
https://stackoverflow.com/questions/64682066/should-stack-yaml-lock-be-checked-into-source-control
Supposedly yes, they should be committed.
| instance ToJSON Schema where | ||
| toJSON = sopSwaggerGenericToJSONWithOpts $ | ||
| mkSwaggerAesonOptions "schema" & saoSubObject ?~ "items" | ||
| mkSwaggerAesonOptions "schema" & saoSubObject .~ ["items", "extensions"] |
There was a problem hiding this comment.
I wonder if it's possible to make extensions injection more implicit, like hardcode it into sopSwaggerGenericToJSON'' — check whether we have extensions in the type and then encode/decode it accordingly. What do you think?
With the current approach I fear we may forget to add this to saoSubObject for some of our types. On the other hand, it becomes more implicit, dunno if it's a good thing.
There was a problem hiding this comment.
I suppose this one can be left for future improvement
|
@PPKFS Do you want to carry out the requested changes or should I? |
|
I've checked locally with our project that generated json does not change 👍 |
|
I can also confirm that the mechanism works for our tool for generating Haskell servers from OpenAPI specs: scarf-sh/tie@d08d9a0#diff-b435607ddb81678ffc30b4fefe883599027eb7e487b8c735ded197ef07947efdR17 |
I'm happy to carry them out after work, unless you're already one step ahead of me :) Also interesting to see we're not the only place with |
|
Oops, very sorry that I offered to make the changes and then promptly forgot. https://github.com/PPKFS/openapi3/tree/alex/aeson-2-support-for-extensions With regards to the point about more implicit injection of |
|
@PPKFS I think you can just open a new PR from your branch! We can then close this one in favour of the new one. As to your second point, I agree it would be nice to have a more implicit injection but I hope we can postpone this kind of change to another contribution and get your work in ASAP. |
|
Anything that can be done to merge this in? @alexbiehl @PPKFS |
|
@ersran9 @PPKFS @maksbotan I think we should probably merge as is. I can report I am using this in Production for some time and am not missing anything. We can improve incrementally for sure. |
maksbotan
left a comment
There was a problem hiding this comment.
Whoops, I've reviewed the wrong one first :)
There's a couple of comments, once they are addressed I'd be happy to merge this.
| -- ** Miscellaneous | ||
| MimeList(..), | ||
| URL(..), | ||
| SpecificationExtensions (..), |
There was a problem hiding this comment.
| sopSwaggerGenericToJSON, sopSwaggerGenericToJSONWithOpts, sopSwaggerGenericParseJSONWithOpts) | ||
| import Data.OpenApi.Internal.Utils | ||
| import Generics.SOP.TH (deriveGeneric) | ||
| import Data.Maybe (catMaybes) |
There was a problem hiding this comment.
this one belongs in the first group
| -- the examples value SHALL override the example provided by the schema. | ||
| , _paramExamples :: InsOrdHashMap Text (Referenced Example) | ||
|
|
||
| , _paramExtensions :: SpecificationExtensions |
| instance ToJSON Schema where | ||
| toJSON = sopSwaggerGenericToJSONWithOpts $ | ||
| mkSwaggerAesonOptions "schema" & saoSubObject ?~ "items" | ||
| mkSwaggerAesonOptions "schema" & saoSubObject .~ ["items", "extensions"] |
There was a problem hiding this comment.
I suppose this one can be left for future improvement
| where | ||
| proxy = Proxy :: Proxy a | ||
|
|
||
| parseAdditionalField :: Object -> Pair -> Parser () |
There was a problem hiding this comment.
there is a copy of this function on line 223 which is unused now, please remove
| in pairs (pairsToSeries (opts ^. saoAdditionalPairs) <> ps) | ||
| where | ||
| proxy = Proxy :: Proxy a | ||
| defs = hcpure (Proxy :: Proxy AesonDefaultValue) defaultValue |
There was a problem hiding this comment.
Copying my comment from #11:
Why is this different from (aesonDefaults proxy) in sopSwaggerGenericToEncoding?
|
It would be amazing to get these improvements in. Is it possible to push it towards merging? 🙏 @alexbiehl @maksbotan |
|
Hi @potocpav! |
|
I would love to be able to use this patch. Is there anything I can do to help get it into the mainline? |
4793b3c to
c2575df
Compare
|
@maksbotan Any chance we can merge this? :) |
This PR is a follow up from #42. Only change compared to #42 is the added support for Aeson 2.