question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: add a new format: plain for type: string

See original GitHub issue

My proposal is that we add a new string type format:

type: string
format: plain

Which limits strings to non-binary strings. The reason that I think this would be helpful is that

type: string

With format unset is generally used as a generic string. However, it should allow in both string and binary string types. Here are some schemas that demonstrate that: Binary is a more specific format constraint on string, so one can have this schema:

composedSchema:
  allOf:
    - type: string
    - type: string
      format: binary

Which will validate for python b'hi'

Can one have a binary date and binary date-time? I suspect not because we don’t know the encoding to go from a sample default/sample/enum string value to an encoded binary value. Do people agree with this point about binary date and datetimes not existing?

What is missing is the ability to constrain a string to only non-binary types. If we had that, then we could reject binary string values and only allow in non-binary strings.

type: string

Allows in ‘hi’ and b’hi’

type: string
format: binary

Allows in b’hi’ only

type: string
format: plain

Would allow in ‘hi’ only and exclude b’hi’

All json payloads that are sending plain text and not binary file data are sending:

type: string
not:
  type: string
  format: binary

which is equivalent to:

type: string
format: plain

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
handrewscommented, May 8, 2021

@spacether format: binary and format: byte no longer exist in OAS 3.1, having been replaced by JSON Schema’s more flexible contentMediaType, contentEncoding, and contentSchema.

The only time you are dealing with an actual octet-stream is when the media type specified in the HTTP Content-Type header or as a part of a multipart form. This is outside of the JSON data model, and not a type: string in the normal sense.

Open API’s Media Type Object and Encoding Object cover whatever aspect of this is not covered by JSON Schema.

When working with a media type compatible with the JSON data model, raw binary is not possible, only encoded binary as indicated by contentEncoding. If there is no contentEncoding, then the string is assumed to be regular JSON string data without any encoding to decode.

I don’t think this proposal applies anymore. format: binary was never a good fit for format (but in fairness to OpenAPI, at the time of OAS 3.0, there weren’t any better options).

0reactions
spacethercommented, May 8, 2021

Thank you for clarifying this. So it sounds like this is no longer applicable in v >= 3.1.0 and that format binary strings cannot be used in place of string type with no formatting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type Parameters Proposal
There have been several proposals for adding type parameters, which can be found through the links above. Many of the ideas presented here...
Read more >
TC39 Proposal: Types as Comments
The Types as Comments proposal aims to simplify working in a modern JavaScript codebases. With Types as Comments, developers can remove a build...
Read more >
C++ formatting library proposal - Google Groups
I'm working on a proposal for a new formatting functionality for the C++ standard library based on the fmt library (https://github.com/fmtlib/fmt).
Read more >
New Freeplane File Format (Proposal)
File types and extensions. A Freeplane file can come in 4 flavors, as single XML document file or as package: Single XML document:...
Read more >
Content controls in Word | Microsoft Learn
Content control improvements in Word 2013; New Word 2013 content control ... A business needs to create a proposal cover page where only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found