Parse error when default value for string array property is a string array
See original GitHub issueI 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:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@padamstx thanks for the heads up, I’m looking into it (in parser) right now.
@gracekarina Thanks for fixing this so quickly! Can’t wait to try it out 😃