Code Monkey home page Code Monkey logo

Comments (7)

maksbotan avatar maksbotan commented on August 24, 2024

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.

ilyakooo0 avatar ilyakooo0 commented on August 24, 2024

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.

ilyakooo0 avatar ilyakooo0 commented on August 24, 2024

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.

maksbotan avatar maksbotan commented on August 24, 2024

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.

ilyakooo0 avatar ilyakooo0 commented on August 24, 2024

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.

maksbotan avatar maksbotan commented on August 24, 2024

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.

ilyakooo0 avatar ilyakooo0 commented on August 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.