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 CBOR #3108

Open
cyberphone opened this issue Dec 29, 2022 · 8 comments
Open

Support for CBOR #3108

cyberphone opened this issue Dec 29, 2022 · 8 comments
Labels
media and encoding Issues regarding media type support and how to encode data (outside of query/path params)

Comments

@cyberphone
Copy link

I have after almost a decade with JSON, decided to use CBOR as the foundation for new designs (except for browser-based applications where the JavaScript/JSON combo still makes sense).

The rationale is here: https://github.com/cyberphone/cbor-everywhere

@MikeRalphson
Copy link
Member

Do you mean support for requestBodies and responses in CBOR format, or exchanging OAS document instances encoded as CBOR? What changes in the specification do you think might be warranted?

https://spec.openapis.org/oas/latest.html#format

Note: While APIs may be defined by OpenAPI documents in either YAML or JSON format, the API request and response bodies and other content are not required to be JSON or YAML.

There is some discussion about CBOR for both representing JSON Schema instances and the object models they operate on over at the JSON Schema spec repo, such as json-schema-org/json-schema-spec#6

@cyberphone
Copy link
Author

I was thinking about request and response bodies.
The data types would be affected since CBOR distinguishes between integer and float types.
The handling of binary data also differ.

@MikeRalphson
Copy link
Member

MikeRalphson commented Feb 22, 2023

As long as bi-directional mapping can be established beween the JSON Schema model and the CBOR model (such as the implicit JSON<=>YAML mapping, or the JSON<=>XML mapping which is supported by the xml keyword which provides hints to perform that mapping), OAS would support CBOR request and response bodies. Do you feel any hinting mechanism would be required here?

JSON Schema also distinguishes between integer and number types. Does CBOR have one or many formats for binary data?

@cyberphone
Copy link
Author

Hinting would probably be needed for binary data since is raw. There is only one binary data format.

@handrews
Copy link
Member

The proposal to loosen the coupling between the OAS and JSON Schema in Moonwalk as noted in the recent "Moonwalk in 2024" blog post could theoretically allow using CDDL with Moonwalk when describing CBOR payloads. Which seems like the best way to support it.

I'm not sure there's much that could be done in an OAS 3.2 other than what @MikeRalphson already suggested, which is define a mapping to the JSON Schema data model and maybe use extension keywords in the schema for hinting.

@handrews handrews added the media and encoding Issues regarding media type support and how to encode data (outside of query/path params) label Jan 28, 2024
@mkschreder
Copy link

I also think CDDL is a fantastic way to bridge openapi and CBOR data. Would be great to have native support for CDDL generation from schema. (maybe there is already? Anyone know?)

@handrews
Copy link
Member

@mkschreder the idea of supporting it in 4.0 "Moonwalk" is mentioned here (it does not yet have its own discussion):

@cyberphone
Copy link
Author

If there will be CBOR support in Open API. it should be restricted to deterministic encoding:
Draft: https://datatracker.ietf.org/doc/draft-ietf-cbor-cde
One of many implementations: https://github.com/cyberphone/CBOR.js#cborjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
media and encoding Issues regarding media type support and how to encode data (outside of query/path params)
Projects
None yet
Development

No branches or pull requests

4 participants