swagger-api / swagger-api/swagger-parser
Inconsistent quoted integer parsing
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
When parsing the following JSON, one instance of "maxItems"="123" [including quotes] for an array type is, correctly, flagged as invalid ("should be Integer") whereas the other is parsed unexpectedly. editor.swagger.io also shows the inconsistent parsing.
It should always be in error (since it is being defined as a string not an int) or parsed from the string to its numeric value (if quoted numerics are being allowed) - being inconsistent leads to confusion...
{
"swagger": "2.0",
"info": {
"description": "",
"version": "1.0.0",
"title": "quotetest"
},
"basePath": "/rootPath",
"schemes": ["https",
"http"],
"consumes": ["application/json"],
"produces": ["application/json"],
"paths": {
"/api": {
"post": {
"operationId": "opIDs",
"parameters": [{
"in": "body",
"name": "opIDs_request",
"description": "request body",
"required": true,
"schema": {
"$ref": "#/definitions/request"
}
}],
"responses": {
"200": {
"description": "normal response",
"schema": {
"$ref": "#/definitions/response_200"
}
}
}
}
}
},
"definitions": {
"request": {
"type": "object",
"properties": {
"rootPath-op": {
"type": "object",
"properties": {
"Header": {
"type": "object",
"properties": {
"CPOAP": {
"description": "The description.",
"type": "array",
"items": {
"type": "string"
},
"maxItems": 122
}
}
}
},
"required": ["ZCONHeader"]
}
}
},
"response_200": {
"x-quotedmaxandminitemsworks": {
"type": "array",
"items": {
"type": "string"
},
"minItems": "0",
"maxItems": "123"
},
"type": "object",
"properties": {
"rootPath-opResponse": {
"type": "object",
"properties": {
"quotedmaxItemsValuebreaks": {
"type": "array",
"maxItems": "10",
"minItems": 0,
"items": {
"type": "string"
}
}
}
}
}
}
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by loading the supplied Swagger JSON through the parser and compare validation of the quoted and unquoted minItems and maxItems values. Trace the parser's handling of these array constraints, then add or update coverage so equivalent quoted values are handled consistently according to the chosen validation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100