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

Support for Specification Extensions in OpenApi Objects #11

Open
mageshb opened this issue Feb 2, 2021 · 8 comments · May be fixed by #21 or #96
Open

Support for Specification Extensions in OpenApi Objects #11

mageshb opened this issue Feb 2, 2021 · 8 comments · May be fixed by #21 or #96

Comments

@mageshb
Copy link

mageshb commented Feb 2, 2021

Following Objects supports Specification Extensions which are used by some tools.

  • OpenAPI
  • Info
  • Contact
  • License
  • Server
  • ServerVariable
  • Paths
  • PathItem
  • OperationObject
  • ExternalDocumentation
  • StyleExamples
  • RequestBody
  • MediaType
  • Encoding
  • Responses
  • Response
  • Callback
  • Example
  • Link
  • Tag
  • Schema
  • XML
  • Security Scheme
  • OAUTH Flows
  • OAUTH Flow
  • SecurityRequirement

I will be able to add this support and send in a pull request if you are interested

@BrechtSerckx
Copy link

We would be interested in extensions too, mainly x-additionalpropertiesname.

@mageshb
Copy link
Author

mageshb commented Feb 8, 2021

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.

@maksbotan
Copy link
Collaborator

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!

@Hazelfire
Copy link

Hey! Love the feature. This is precisely how I would have gone about implementing extensions, would love to see a pull request for this

@mageshb
Copy link
Author

mageshb commented Apr 20, 2021

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?

@mageshb mageshb linked a pull request Apr 21, 2021 that will close this issue
@PilchardFriendly
Copy link

I would find this extremely useful - did you decide on an approach?

@alexbiehl
Copy link

I would find this extremely useful

Yeah, me too! Any movement on the topic?

@jllang
Copy link

jllang commented Jul 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants