Open mageshb opened 3 years ago
We would be interested in extensions too, mainly x-additionalpropertiesname.
Have implemented extension support for few OpenApi objects. Kindly let me know if this approach is fine, in that case I will be complete it for rest of the object and send in a PR.
Implementation ToJSON
& FromJSON
instance for Schema
seems to have mismatch.
In ToJSON, it is mentioned as a SubObject of items
https://github.com/biocad/openapi3/blob/master/src/Data/OpenApi/Internal.hs#L1261
Whereas in FromJSON, it is SubObject of paramSchema
https://github.com/biocad/openapi3/blob/master/src/Data/OpenApi/Internal.hs#L1398
https://github.com/biocad/openapi3/blob/master/src/Data/OpenApi/Internal.hs#L1527
Is this not a bug?
@BrechtSerckx Because of the above mentioned doubt, I was not able to add extension field for Schema Object. Once that is cleared, I will be able to add the support for the extension you have mentioned.
Hi! Thank you for this work! I will take a look in a couple of days and tell you what I think. Sorry for the delay!
Hey! Love the feature. This is precisely how I would have gone about implementing extensions, would love to see a pull request for this
Hi @Hazelfire,
I'm yet to add extension for few Objects like Schema
, Responses
, Callback
, XML
, OAUTH Flow
.
Problem mainly is these object already have sub-object.
There are two ways we can handle this issue.
1) Change _saoSubObject in SwaggerAesonOptions
to List to support multiple subobjects.
2) Write custom the FromJSON & ToJSON instance like below
instance FromJSON Responses where
parseJSON (Object o) = Responses
<$> o .:? "default"
- <*> parseJSON (Object (HashMap.delete "default" o))
+ <*> parseJSON (Object (HashMap.filterWithKey (\k _ -> not $ isExt k)
+ $ HashMap.delete "default" o))
+ <*> case HashMap.filterWithKey (\k _ -> isExt k) o of
+ exts | HashMap.null exts -> pure (SpecificationExtensions mempty)
+ | otherwise -> parseJSON (Object exts)
@maksbotan @Hazelfire Any thoughts on this?
I would find this extremely useful - did you decide on an approach?
I would find this extremely useful
Yeah, me too! Any movement on the topic?
I'd especially appreciate the support for tags. In my previous project, we added tags to our endpoints using lenses, but we had a Swagger 2.0 API that was generated by another library. I don't know how to add tags to my OpenAPI 3.0 specs and I haven't found enough documentation for this and I've asked numerous people at different events and chatrooms about it.
Following Objects supports Specification Extensions which are used by some tools.
I will be able to add this support and send in a pull request if you are interested