Comments (7)
mempty
for Operation
will just set servers = []
and default ToJSON implementation will omit all empty lists, so in the resulting JSON there will be no servers
field at all.
Is there a problem with that behavior?
from openapi3.
The behavior becomes problematic when you try to parse openapi specifications from a file. (The FromJSON
instance)
(the exact same problem with #14)
from openapi3.
Or does the instance parse omitted fields as empty?
In any case, an empty list and null
are semantically distinct, leading to different specifications.
from openapi3.
Decoder will set []
for missing field. null
is allowed as well:
λ> decode' @Operation "{\"responses\": {}}" ^? _Just . servers
Just []
λ> decode' @Operation "{\"responses\": {}, \"servers\": null}" ^? _Just . servers
Just []
This decisions re encoding/decoding exist already in swagger2
package.
from openapi3.
Decoder will set [] for missing field. null is allowed as well
Well, this is not a good thing. "An operation needs no authorization" ([]
) and "Inherit the authorization needed from the parent context" (null
) are two completely different things, and it is a good thing to distinguish between them.
The current behavior means that there is no way of setting "Inherit the authorization needed from the parent context" when encoding a spec, and when reading a spec "Inherit the authorization needed from the parent context" becomes "An operation needs no authorization". I don't think this is desired behavior.
This decisions re encoding/decoding exist already in swagger2 package.
Maybe I misunderstand something. Is the point of this package to match swagger2
as closely as possible? Or is it to implement the OpenApi 3 spec?
from openapi3.
Well, this is not a good thing. "An operation needs no authorization" ([]) and "Inherit the authorization needed from the parent context" (null) are two completely different things, and it is a good thing to distinguish between them.
Is null
even allowed by OpenAPI spec? I'm not sure, but if it is, and has the meaning you described, then the package should be fixed ofc.
Maybe I misunderstand something. Is the point of this package to match swagger2 as closely as possible? Or is it to implement the OpenApi 3 spec?
No, I've just provided the historical context. Of course if those decisions happen to be wrong, they must be changed. I just didn't touch encoding code at all, hoping that it is OK.
from openapi3.
Is null even allowed by OpenAPI spec? I'm not sure, but if it is, and has the meaning you described, then the package should be fixed ofc.
This package already serializes fields as missing. As far as I understand, in most cases a missing field and a field with null
are interchangeable.
I provided an excerpt from the OpenApi 3 spec in my initial comment. Are you suggesting that it is implying the omission of the field, instead of setting it to null?
In either case, even if the correct behavior is to omit the field (I am now leaning towards that), the way to encode both a missing field, and null
in haskell would be with a Maybe
(The difference being in the ToJSON
instance).
from openapi3.
Related Issues (20)
- `encodePretty` should be exposed from `Data.OpenApi`
- Invalid schema with types with primes (`'`)
- Generic polymorphic schema handle lists differently to aeson HOT 2
- Outdated documentation re sum encoding differs ToSchema/ToJSON? HOT 1
- Wrong format when generating empty scopes map HOT 2
- Exception when parsing newer OpenApi3 schemas HOT 4
- Add `nullable` attribute HOT 4
- _OpenApiItemsArray and _OpenApiItemsObject should be Prisms, not Reviews
- invalid schema HOT 1
- Structural error at components.schemas.AggregateMRQuery.properties.select.items.items should be object HOT 2
- SecurityDefinitions missing "Index" and "IxValue" type family instances
- SecurityDefinitions missing "Ixed" and "At" type-class instances
- Allow GHC-9.6
- Mismatch between ToJSON and ToSchema with nullary single-record constructor
- How to implement allOperations for optics? HOT 2
- Hardcoded references
- add `ToSchema Schema` instance
- validateJSON semantics with `allOf` seem incorrect
- Why are the schemas different for `ToParamSchema UUID` and `ToSchema UUID`
- Prefix stripping when a `$ref` is parsed as a `Referenced` is confusing HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi3.