Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@openapitools/openapi-generator-cli
Advanced tools
A npm package wrapper for OpenAPI Generator (https://github.com/OpenAPITools/openapi-generator), generates which API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
@openapitools/openapi-generator-cli is a command-line interface tool that allows you to generate API client libraries, server stubs, API documentation, and configuration automatically from an OpenAPI Specification. It supports a wide range of languages and frameworks, making it a versatile tool for API development.
Generate Client Libraries
This command generates a JavaScript client library from the OpenAPI specification available at the provided URL. The generated code will be placed in the './generated-client' directory.
npx @openapitools/openapi-generator-cli generate -i https://petstore.swagger.io/v2/swagger.json -g javascript -o ./generated-client
Generate Server Stubs
This command generates a Spring server stub from the OpenAPI specification available at the provided URL. The generated code will be placed in the './generated-server' directory.
npx @openapitools/openapi-generator-cli generate -i https://petstore.swagger.io/v2/swagger.json -g spring -o ./generated-server
Generate API Documentation
This command generates HTML documentation from the OpenAPI specification available at the provided URL. The generated documentation will be placed in the './generated-docs' directory.
npx @openapitools/openapi-generator-cli generate -i https://petstore.swagger.io/v2/swagger.json -g html2 -o ./generated-docs
Custom Templates
This command generates a JavaScript client library using custom templates located in the './custom-templates' directory. The generated code will be placed in the './generated-client' directory.
npx @openapitools/openapi-generator-cli generate -i https://petstore.swagger.io/v2/swagger.json -g javascript -t ./custom-templates -o ./generated-client
swagger-codegen-cli is a command-line tool for generating client libraries, server stubs, API documentation, and configuration from a Swagger/OpenAPI Specification. It is the predecessor to @openapitools/openapi-generator-cli and offers similar functionalities but with fewer updates and community support.
openapi-generator is a fork of swagger-codegen that offers more features, better support for modern languages and frameworks, and a more active community. It is essentially the core library that @openapitools/openapi-generator-cli wraps around for CLI usage.
swagger-jsdoc is a tool that generates Swagger/OpenAPI documentation from JSDoc comments in your code. While it doesn't generate client libraries or server stubs, it is useful for creating and maintaining API documentation directly from your codebase.
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (both 2.0 and 3.0 are supported). Please see OpenAPITools/openapi-generator
You need to execute openapi-generator-cli
instead of openapi-generator
from now on.
To make that happen, a version management was added to the package.
The first time you run the command openapi-generator-cli
the last stable version
of OpenAPITools/openapi-generator is downloaded by default.
That version is saved in the file openapitools.json. Therefore you should include this file in your version control, to ensure that the correct version is being used next time you call the command.
If you would like to use a different version of the OpenAPITools/openapi-generator, you could change it by using one of the following commands:
openapi-generator-cli version-manager list
openapi-generator-cli version-manager set <versionTags...>
You will now be able to configure the code generation in openapitools.json. This makes it more convenient to generate code for every file that matches the given glob expression. For more information, please check out the configuration documentation below.
npm install @openapitools/openapi-generator-cli
or using yarn
yarn add @openapitools/openapi-generator-cli
After the installation has finished you can run npx openapi-generator-cli
or add a script like this:
{
"name": "my-cool-package",
"version": "0.0.0",
"scripts": {
"my-awesome-script-name": "openapi-generator-cli generate -i docs/openapi.yaml -g typescript-angular -o generated-sources/openapi --additional-properties=ngVersion=6.1.7,npmName=restClient,supportsES6=true,npmVersion=6.9.0,withInterfaces=true",
}
}
Note the whitespace sensitivity when using multiple additional-properties:
--additional-properties=ngVersion=6.1.7,npmName=restClient,supportsES6=true,npmVersion=6.9.0,withInterfaces=true
npm install -g @openapitools/openapi-generator-cli
or using yarn
yarn global add @openapitools/openapi-generator-cli
After the installation has finished you can run openapi-generator-cli
Mac/Linux:
openapi-generator-cli generate -g ruby -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o /var/tmp/ruby-client
Windows:
openapi-generator-cli generate -g ruby -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o C:\temp\ruby-client
If you have installed the package locally and executed the command openapi-generator-cli
at least once,
you will find a new file called openapitools.json along with the package.json. Please add this file to your VCS.
Initially the file has the following content:
{
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "4.3.1" // or the current latest version ;)
}
}
This configuration indicates the following:
Further it is also possible to configure generators, for example:
{
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "4.3.1",
"storageDir": "~/my/custom/storage/dir", // optional
"generators": { // optional
"v2.0": { // any name you like (just printed to the console log)
"generatorName": "typescript-angular",
"output": "#{cwd}/output/v2.0/#{ext}/#{name}",
"glob": "examples/v2.0/{json,yaml}/*.{json,yaml}",
"additionalProperties": {
"ngVersion": "6.1.7",
"npmName": "restClient",
"supportsES6": "true",
"npmVersion": "6.9.0",
"withInterfaces": true
}
},
"v3.0": { // any name you like (just printed to the console log)
"generatorName": "typescript-fetch",
"output": "#{cwd}/output/v3.0/#{ext}/#{name}",
"glob": "examples/v3.0/petstore.{json,yaml}"
}
}
}
}
If openapi-generator-cli generate
is called without further arguments, then the configuration
is automatically used to generate your code. 🎉
placeholder | description | example |
---|---|---|
name | just file name | auth |
Name | just file name, but starting with a capital letter | Auth |
cwd | the current cwd | /Users/some-user/projects/some-project |
base | file name and extension | auth.yaml |
path | full path and filename | /Users/some-user/projects/some-project/docs/auth.yaml |
dir | path without the filename | /Users/some-user/projects/some-project/docs |
relDir | directory name of file relative to the glob provided | docs |
relPath | file name and extension of file relative to the glob provided | docs/auth.yaml |
ext | just file extension | yaml |
Custom generators can be used by passing the --custom-generator=/my/custom-generator.jar
argument.
Please refer to the official openapi-generator docs for more information about the possible arguments and a detailed usage manual of the command line interface.
npm install @openapitools/openapi-generator-cli@previous
npm i @openapitools/openapi-generator-cli@1.0.18-4.3.1
or using yarn
yarn add @openapitools/openapi-generator-cli@previous
yarn add @openapitools/openapi-generator-cli@1.0.18-4.3.1
Please leave a star.
FAQs
A npm package wrapper for OpenAPI Generator (https://github.com/OpenAPITools/openapi-generator), generates which API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
The npm package @openapitools/openapi-generator-cli receives a total of 513,789 weekly downloads. As such, @openapitools/openapi-generator-cli popularity was classified as popular.
We found that @openapitools/openapi-generator-cli demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.