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.

Empty default in schema is parsed as null

See original GitHub issue

Parser version:

2.0.2

Description:

OAS 3 spec (partial):

components:
  parameters:
    example:
      name: example
      description: example
      in: query
      required: false
      schema:
        type: array
        items:
          type: string
        default: ''

The parameter schema parser treats empty strings as null.

schema.getDefault() returns null.

The following results in a proper default value being set:

components:
  parameters:
    example:
      name: example
      description: example
      in: query
      required: false
      schema:
        type: array
        items:
          type: string
        default: 'a,b,c'

schema.getDefault() returns "a,b,c".

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
webroncommented, Aug 26, 2018

That’s where it gets complicated. Not sure there is a way to do it, as it’s an edge case.

Theoretically, you could set the default value to [] which is indeed an empty JSON array. However, the value of the array in this case is not a JSON, especially with the defaults for query parameters having style: form, explode: true by default - suggesting there’s no real way of representing that. I’d recommend filing a ticket on the spec asking that question. We may simply agree that a JSON array value would be representative of such values regardless of how those are being converted to the request.

That said, in your specific example, one might argue that there’s no point providing a default value of an empty array as it most likely does not affect the documentation nor implementation.

0reactions
gracekarinacommented, Jun 20, 2019

Hi, the scope of the issue changed, the validation of this new scope made in another PR. Thanks @jason-cohen for reporting this and sorry for the long reply. I will close this because is no longer an issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Empty list as default value in AVRO array - Stack Overflow
Using the Builder of the parsed avro Schema class would fill the "string_arr" field with an empty array per default. Save this answer....
Read more >
Handling JSON null and empty arrays and objects - IBM
Handling null and empty arrays and objects used in JSON data is described. JSON data has the concept of null and empty arrays...
Read more >
Handling NULL in Parse JSON - Power Platform Community
Solved: I have an API which has the following characteristics: Schema: ... any way to create a schema which allows null values in...
Read more >
Writing a schema - FlatBuffers - Google
Only scalar values can have defaults, non-scalar (string/vector/table) fields default to NULL when not present. You generally do not want to change default...
Read more >
Setting default values in the schema of a component in a Job
You can set default values in the schema of certain components to replace null values retrieved from the data source. Note: At present,...
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