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.

Examples not reads when `format: byte`

See original GitHub issue

Hello there,

From the openapi-style-validator project, we have an issue with properties of type string and format byte where the example is not read: https://github.com/OpenAPITools/openapi-style-validator/issues/132

Schema:

  schemas:
    Response:
      required:
        - content
      properties:
        content:
          type: string
          format: byte
          example: "VGhpc1Nob3VsZFBhc3MK"

Expected: An OpenAPI with example set for the content property.

Actual: example is null.

We do not know if this is expected behaviour or an issue on the parser, can someone tell us more on that “issue” ?

Thanks

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
frantumacommented, Mar 28, 2022

@gervaisb

we have added indeed such conversion in https://github.com/swagger-api/swagger-core/pull/4147, therefore you can use it if it fits your needs (by using parser “as is” , with no swaggerParserBinaryAsString property/env set).

The first possible issue with this approach is that the conversion / data binding is opinionated, as it uses getBytes() to encode the string into bytes, while e.g. the serialized string could be meant to be a Base64 encoded representation of the bytes (Jackson e.g. uses Base64 for default binding of string to byte[])

Another issue is serialization of the parsed string, in this case the serialized value will be encoded in Base64, resulting in a different string from the one parsed.

We might choose to try using Base64 in the cast method above, but again this would be an opinionated choice, given also that e.g. example is of any type in OAS 3.0, possibly including any encoding/representation of binary values

An additional issue is serialization to YAML; YAML is capable to represent binary using tags, and indeed default serialization uses that, therefore a YAML version of the same spec, with the same string value in example as the one in JSON version, would not be parsed correctly (would actually break).

example: !!binary |-
  Y2FjY2E=

We could further address the points above by e.g. providing more options and addressing the different cases, but on top of adding quite some complexity and being not trivial, the expected behaviour would be dependent on the specific spec.

0reactions
frantumacommented, Mar 29, 2022

no fixed ETA but probably within first week of April

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problems with writing bytes format of string data in Text File in ...
Your first file is binary, in a way. It just so happens that bytes represent human-readable text. The f and F in your...
Read more >
Understanding Big and Little Endian Byte Order
If we store and read data one byte at a time, it will work on any computer. ... This example does not depend...
Read more >
struct — Interpret bytes as packed binary data — Python 3.11 ...
Iteratively unpack from the buffer buffer according to the format string format. This function returns an iterator which will read equally sized chunks...
Read more >
read
The read() function shall attempt to read nbyte bytes from the file associated with the open file descriptor, fildes, into the buffer pointed...
Read more >
FileStream.Read Method (System.IO) - Microsoft Learn
Reads a block of bytes from the stream and writes the data in a given buffer. ... The following example reads the contents...
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