APIDevTools / swagger-parser

Swagger 2.0 and OpenAPI 3.0 parser/validator
https://apitools.dev/swagger-parser
MIT License
1.08k stars 153 forks source link

Multiple minor problems parsing docker API spec #250

Closed s-h-a-d-o-w closed 10 months ago

s-h-a-d-o-w commented 10 months ago

My source file (I converted the original spec to v3 and fixed an invalid regex): https://gist.github.com/s-h-a-d-o-w/1e6ddd918d93181473883ecd8375d85d

Doing await SwaggerParser.parse("./docker.json") results in the following:

BEFORE
            "description": "Assign the specified name to the container. Must match\n`\/?[a-zA-Z0-9][a-zA-Z0-9_.-]+`.\n",
AFTER
            "description": "Assign the specified name to the container. Must match\n`/?[a-zA-Z0-9][a-zA-Z0-9_.-]+`.\n",

BEFORE
            "example": 1629574695515050031
AFTER
            "example": 1629574695515050000

While the escape character removal fortunately doesn't happen in the actual pattern when it comes to the first problem, I tried changing from example to default and the number is changed in that case as well!

s-h-a-d-o-w commented 10 months ago

I just tried to trace this problem myself and realized that it seems all you're doing is using JSON.parse: https://github.com/APIDevTools/json-schema-ref-parser/blob/main/lib/parsers/json.ts#L38

So I compared and... the result matches. Strange but I guess the problem actually lies somewhere here: https://chromium.googlesource.com/v8/v8.git/+/refs/heads/main/src/json/json-parser.cc

s-h-a-d-o-w commented 10 months ago

If someone stumbles across this - there's no problem.

The number changes because it's larger than the max safe integer in JS. And when it comes to the text change - I didn't escape the backslash. 🙈