Doesn’t work: JsonParseException: Unrecognized token ‘openapi’: was expecting (JSON String, Number, Array, Object or token ‘null’, ‘true’ or ‘false’)
Explanation of the problem
The error occurred while running the following command:
docker run --rm -v /etc/passwd:/etc/passwd:ro -u (id -u):(id -g) -v (pwd):(pwd) -w (pwd) openapitools/openapi-diff specifications/api/swagger.yaml.v2020-11-03 specifications/api/swagger.yaml.v2020-11-17-135-g5d316c5ef --markdown api-diff.md
It seems that the error occurred during the execution of a Docker command that runs the openapi-diff tool. The tool failed to read the resource listing due to an unrecognized token ‘openapi’, which indicates that the input file might have an incorrect format. Moreover, an unexpected exception occurred, suggesting that there might be an issue with reading the old OpenAPI spec.
The input files for the openapi-diff tool can be accessed through the provided URL. It is recommended to check the input files for any syntax errors or compatibility issues. Additionally, the Docker command options should be reviewed to ensure that they are set correctly for the intended operation.
Troubleshooting with the Lightrun Developer Observability Platform
Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.
- Instantly add logs to, set metrics in, and take snapshots of live applications
- Insights delivered straight to your IDE or CLI
- Works where you do: dev, QA, staging, CI/CD, and production
Start for free today
Problem solution for Doesn’t work: JsonParseException: Unrecognized token ‘openapi’: was expecting (JSON String, Number, Array, Object or token ‘null’, ‘true’ or ‘false’)
Based on the top answers, it seems like the issue with YAML merge keys is a known problem, especially with Jackson (jackson-dataformat-yaml). YAML merge keys are not very well specified and not very well supported, and multiple sequential merge keys on the same level can cause issues with the stack. In fact, YAML 1.2 removes them altogether, so it’s recommended not to rely on them.
To address this issue, one suggestion is to use a YAML spec that follows the recommended guidelines. The top answer provides a YAML spec and diff that have been used successfully. Additionally, setting the log level of openapi-diff to INFO or WARN can provide a more detailed error description.
Overall, it’s important to be aware of the limitations of YAML merge keys and consider alternative approaches to avoid potential issues with the stack.
Other popular problems with OpenAPITools OpenAPI Generator CLI
Problem: “ERESOLVE overriding peer dependency” Warning
When running the command “npm i” with a package.json file that includes the OpenAPI Generator CLI, some users may encounter a warning message stating “ERESOLVE overriding peer dependency”. This warning message indicates that there is a conflict between the version of a dependency specified in the OpenAPI Generator CLI package and the version of that dependency specified in another package in the project.
One way to resolve this issue is to update the conflicting package to the version specified in the OpenAPI Generator CLI package. Another solution is to specify the desired version of the conflicting dependency in the project’s package.json file. This can be done by adding a “resolutions” field in the package.json file and specifying the desired version for the conflicting dependency.
Problem: Error when running OpenAPI Generator CLI
When attempting to run the OpenAPI Generator CLI, some users may encounter an error such as “command not found” or “no such file or directory”. This may be caused by the OpenAPI Generator CLI not being installed or not being installed correctly.
To resolve this issue, ensure that the OpenAPI Generator CLI is installed by running the command “npm install @openapitools/openapi-generator-cli” and verify that the installation was successful. If the issue persists, try uninstalling and reinstalling the package.
Problem: Incompatibility with Node.js version
The OpenAPI Generator CLI may not be compatible with certain versions of Node.js. This can lead to issues such as syntax errors or unexpected behavior when running the CLI.
To resolve this issue, ensure that the Node.js version in use is compatible with the version of the OpenAPI Generator CLI package. The package’s documentation should list the compatible Node.js versions. If necessary, update the Node.js version or update the OpenAPI Generator CLI package to a version that is compatible with the current Node.js version.
A brief introduction to Open APITools OpenAPI Generator CLI
This tool can be integrated with different development environments and build systems, such as Gradle, Maven, and npm. It also supports custom templates, which can be used to customize the generated code. Additionally, it supports multiple languages and frameworks, allowing developers to generate code for their preferred programming languages and frameworks. This tool can save developers a significant amount of time and effort when creating API client libraries, server stubs, and documentation.
Most popular use cases for OpenAPITools OpenAPI Generator CLI
- One use of the OpenAPITools OpenAPI Generator CLI is to generate client code for various programming languages from an OpenAPI specification. A code block demonstrating this use would be:
- Another use of the OpenAPITools OpenAPI Generator CLI is to generate server code for various programming languages from an OpenAPI specification. A code block demonstrating this use would be:
openapi-generator generate -i http://petstore.swagger.io/v2/swagger.json -g spring
This command generates a Spring server in the current directory using the OpenAPI specification at the specified URL.
- The OpenAPITools OpenAPI Generator CLI can also be used to validate an OpenAPI specification. A code block demonstrating this use would be:
openapi-generator validate -i http://petstore.swagger.io/v2/swagger.json
This command validates the OpenAPI specification at the specified URL. If the specification is valid, the command will print “valid” to the console. If the specification is invalid, the command will print the validation errors to the console.
It’s Really not that Complicated.
You can actually understand what’s going on inside your live applications. It’s a registration form away.