biocad / openapi3

OpenAPI 3.0 data model
BSD 3-Clause "New" or "Revised" License
39 stars 54 forks source link

Expanding the possible values of a Schema example beyond `Value` #54

Open theophile-scrive opened 2 years ago

theophile-scrive commented 2 years ago

Hi @maksbotan!

At our workplace we use OpenAPI3 and are very grateful for the work that was put in it. Recently we have taken to move away from using Aeson's Value, as it does not preserve key ordering. While JSON applications should not rely on it, it's actually quite useful for examples as similar fields are declared next to another, and we usually want some "Id" field to be the first one displayed. For example, last_name and first_name should be together.

Now, I'm not suggesting to break the compatibility by changing the type of _schemaExample :: Maybe Value to something incompatible, but rather open more possibilities by having something like an existentially-quantified type:

data Jsonable = forall a. ToJSON a => Jsonable a

_schemaExample :: Maybe JSONable

and use directly encode in the library to render the ByteString.

How does this sound? I can submit a PR if you agree on the design. :)

theophile-scrive commented 1 year ago

@maksbotan friendly ping :)