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.

Parse error when default value for string array property is a string array

See original GitHub issue

I have an OpenAPI 3 apispec with the following schema defined:

            "DocFilterSettings": {
                "type": "object",
                "description": "This model describes the attributes used to filter a document.",
                "properties": {
                    "tag_list": {
                        "description": "This is the set of tags to include in the output.",
                        "type": "array",
                        "items": {
                            "type": "string"
                        },
                        "default": [
                            "h1",
                            "h2"
                        ]
                    }
                }
            }

So… a property which is an array of strings with a default value which is also an array of strings. Unfortunately, when I use swagger-parser v2.0.8 to read in this apispec, I get this error returned in the SwaggerParseResult object:

attribute components.schemas.DocFilterSettings.default is not of type `string`

I initially found this in swagger-parser v2.0.4 but it also occurs with the latest (2.0.8).

It seems like the default value for an array of strings should itself be an array of strings, no? Also, a secondary issue is that the error message doesn’t reference the actual name of the schema property which was found to be in error.

Here’s a small code snippet (part of a unit test) which shows the code I’m using to read in the apispec:

        ParseOptions options = new ParseOptions();
        options.setResolve(true);
        options.setResolveCombinators(true);
        SwaggerParseResult parseResult = new OpenAPIParser().readLocation(path, null, options);
        if (parseResult.getMessages() != null && !parseResult.getMessages().isEmpty()) {
            parseResult.getMessages().forEach(s -> System.out.println(s));
            fail("Error while loading apispec!");
        }

        OpenAPI apispec = parseResult.getOpenAPI();
        assertNotNull(apispec);

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
gracekarinacommented, Feb 15, 2019

@padamstx thanks for the heads up, I’m looking into it (in parser) right now.

0reactions
padamstxcommented, Feb 15, 2019

@gracekarina Thanks for fixing this so quickly! Can’t wait to try it out 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why I'm getting parse error in accessing an array value ...
1 Answer 1 ... When your array variable is already in double quotes " at that time you don't have to add any...
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
Strings - Manual - PHP
It provides a way to embed a variable, an array value, or an object property in a string with a minimum of effort....
Read more >
Array | Apple Developer Documentation
An array can store any kind of elements—from integers to strings to classes. ... number of default values, use the Array(repeating:count:) initializer.
Read more >
ConvertFrom-Json (Microsoft.PowerShell.Utility)
The ConvertFrom-Json cmdlet converts a JavaScript Object Notation (JSON) formatted string to a custom PSObject or Hashtable object that has a property for ......
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