使用OpenAPI JSON Schema Genemator从OpenAPI 3.0.0-3.1.0文档中自动生成客户端SDK。该项目是一个代码生成器,专注于支持所有OpenAPI和JSON模式功能。
OpenAPI JSON模式生成器允许给定一个OpenAPI文档(支持3.0.0.0-3.1.0*)自动生成API客户端库(SDK Generation)。该项目着重于使输出100%符合OpenAPI + JSON模式规格。目标是完全支持OpenAPI +中定义的所有内容,其中包含的JSON模式规格,以便开发人员可以使用所有这些功能。
目前,支持以下语言/框架:
| 特征 | Python | 爪哇 | 科特林 |
|---|---|---|---|
| 发电机状态 | 稳定的 | 稳定的 | 稳定的 |
| OpenAPI v3.0.0-3.1.0摄入 | x | x | x |
| JSON模式2020-12支持(组件/模式) | x | x | x |
| 组件模式类 +生成的文档 | x | x | x |
| 为其他组件类型生产的文档: 标题,参数,请求bodies,resspons,SecuritySchemes | x | x | |
| 生成端点的方法 为他们生成的发送/接收JSON +文档 | x | x |
from 1var , hi-there等我们使用Discord服务器作为提出问题并互相帮助的地方。它提供的功能与Slack非常相似。您可以在这里加入我们:https://discord.gg/mhb8wequyq
是的;欢迎捐款!如果您想用任何语言添加新的服务器脚手架,客户端SDK或文档生成器,请提交PR。
自2010年最初创建以来,OpenAPI规范已进行了3个修订。OpenApi-Json-Schema-generator项目具有以下与OpenAPI规范的兼容性:
| OpenAPI JSON模式生成器版本 | OpenAPI规格兼容性 |
|---|---|
| 3.3.0+ | 3.0.0-3.1.0* |
| 3.1.0-3.2.1 | 3.0.0-3.1.0 |
| 1.0.0-3.0.0 | 3.0.0-3.0.3 |
OpenAPI v3.1.0规范支持包括这些新/更新的2020-12 JSON模式关键字:
注意:这些功能也可以在“发电机文档架构”功能中看到
要从源构建,您需要在$PATH:
Java 11
Apache Maven 3.9.3或更高
克隆项目后,您可以使用此命令从源构建它:
mvn clean install默认构建包含最小的静态分析(通过CheckStyle)。要使用PMD和Spotbugs运行您的构建,请使用static-analysis配置文件:
mvn -Pstatic-analysis clean installDocker映像是独立可执行的。它可以用作通过Homebrew安装安装的替代方法,也可以用作无法安装Java或升级已安装版本的开发人员。
要使用此图像生成代码,您需要将本地位置作为音量安装。
例子:
docker run --rm -v " ${PWD} :/local " openapijsonschematools/openapi-json-schema-generator-cli generate
-i https://raw.githubusercontent.com/openapi-json-schema-tools/openapi-json-schema-generator/master/src/test/resources/3_0/petstore.yaml
-g python
-o /local/out/python生成的代码将位于当前目录中的./out/python下。
您可以使用bin/run-in-docker.sh来完成所有开发。此脚本将您的本地存储库映射到Docker容器中的/gen 。它还将~/.m2/repository映射到适当的容器位置。
执行mvn package :
git clone https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
cd openapi-json-schema-generator
./bin/run-in-docker.sh mvn package现在可以在您的工作目录中访问构建工件。
一旦构建, run-in-docker.sh将充当Openapi-Json-Schema-generator-CLI的可执行文件。要生成代码,您需要输出到/gen (例如/gen/out )下的目录。例如:
./bin/run-in-docker.sh help # Executes 'help' command for openapi-json-schema-generator-cli
./bin/run-in-docker.sh list # Executes 'list' command for openapi-json-schema-generator-cli
./bin/run-in-docker.sh /gen/bin/python-petstore.sh # Builds the Python client
./bin/run-in-docker.sh generate -i src/test/resources/3_0/petstore.yaml
-g go -o /gen/out/python-petstore -p packageName=petstore_api # generates python client, outputs locally to ./out/python-petstore 如果发生这样的错误,只需执行MVN CLEAS install -U命令:
org.apache.maven.lifecycle.lifecycleexecutionExction exception:无法执行目标org.apache.maven.maven.plugins:maven-surefire-plugin:2.19.1:2.19.1:test(test(devault-test)在项目OpenApi-json-json-schema-schema-generator上执行不合时宜: org.apache.maven.plugins:maven-surefire-plugin:2.19.1:测试:java.lang.exceptionininitializererror不能被施加到java.io.io.io.io.ioexception
./run-in-docker.sh mvn clean install -U无法执行目标org.fortasoft:gradle-maven-plugin:1.0.8:project openapi-json-json-schema-gradle-plugin-plugin-mvn-mvn-wrapper上的invoke(默认) 'https://services.gradle.org/distributions/gradle-4.7-bin.zip'
现在:没有解决方案:|
要为petstore.yaml生成一个python客户端,请运行以下内容
git clone https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
cd openapi-json-schema-generator
mvn clean package
java -jar target/openapi-json-schema-generator-cli.jar generate
-i https://raw.githubusercontent.com/openapi-json-schema-tools/openapi-json-schema-generator/master/src/test/resources/3_0/petstore.yaml
-g python
-o /var/tmp/python_api_client (如果您在Windows上,请用java -jar targetopenapi-json-schema-generator-cli.jar generate -i https://raw.githubusercontent.com/openapi-json-schema-tools/openapi-json-schema-generator/master/src/test/resources/3_0/petstore.yaml -g python -oc:temppython_api_client )
要获取可用java -jar target/openapi-json-schema-generator-cli.jar help generate一般选项列表
要获取Python指定选项的列表(可以通过-c选项将其传递给发电机),请运行java -jar target/openapi-json-schema-generator-cli.jar config-help -g python
您可以针对PetStore API建立客户,如下所示:
./bin/generate-samples.sh ./bin/generate_samples_configs/python.yaml(在Windows上,请安装Windows的Git Bash以运行上面的命令)
此脚本将使用此命令运行生成器:
java -jar target/openapi-json-schema-generator-cli.jar generate
-i https://raw.githubusercontent.com/openapijsonschematools/openapi-json-schema-generator/master/src/test/resources/3_0/petstore.yaml
-g python
-t src/main/resources/python
--additional-properties packageName=petstore_api
-o samples/client/petstore/python带有许多选项。 python选项记录在此处。
您还可以使用help generate命令获得选项(下面仅显示部分结果):
NAME
openapi-json-schema-generator-cli generate - Generate code with the specified
generator.
SYNOPSIS
openapi-json-schema-generator-cli generate
[(-a <authorization> | --auth <authorization>)]
[--api-name-suffix <api name suffix>] [--api-package <api package>]
[--artifact-id <artifact id>] [--artifact-version <artifact version>]
[(-c <configuration file> | --config <configuration file>)] [--dry-run]
[(-e <templating engine> | --engine <templating engine>)]
[--enable-post-process-file]
[(-g <generator name> | --generator-name <generator name>)]
[--git-host <git host>] [--git-repo-id <git repo id>]
[--git-user-id <git user id>] [--global-property <global properties>...]
[--group-id <group id>] [--hide-generation-timestamp]
[--http-user-agent <http user agent>]
[(-i <spec file> | --input-spec <spec file>)]
[--ignore-file-override <ignore file override location>]
[--ints-allowed-for-float-double-formats]
[--invoker-package <invoker package>] [--minimal-update]
[--model-name-prefix <model name prefix>]
[--model-name-suffix <model name suffix>]
[(-o <output directory> | --output <output directory>)] [(-p <additional properties> | --additional-properties <additional properties>)...]
[--package-name <package name>] [--release-note <release note>]
[--remove-enum-value-prefix] [--remove-operation-id-prefix]
[(-s | --skip-overwrite)] [--skip-operation-example]
[--skip-validate-spec] [--strict-spec <true/false strict behavior>]
[(-t <template directory> | --template-dir <template directory>)]
[(-v | --verbose)]
OPTIONS
-a <authorization>, --auth <authorization>
adds authorization headers when fetching the OpenAPI definitions
remotely. Pass in a URL-encoded string of name:header with a comma
separating multiple values
--api-name-suffix <api name suffix>
Suffix that will be appended to all API names ('tags'). Default:
Api. e.g. Pet => PetApi. Note: Only ruby, python, jaxrs generators
support this feature at the moment.
--api-package <api package>
package for generated api classes
--artifact-id <artifact id>
artifactId in generated pom.xml. This also becomes part of the
generated library's filename
--artifact-version <artifact version>
artifact version in generated pom.xml. This also becomes part of the
generated library's filename
-c <configuration file>, --config <configuration file>
Path to configuration file. It can be JSON or YAML. If file is JSON,
the content should have the format {"optionKey":"optionValue",
"optionKey1":"optionValue1"...}. If file is YAML, the content should
have the format optionKey: optionValue. Supported options can be
different for each language. Run config-help -g {generator name}
command for language-specific config options.
--dry-run
Try things out and report on potential changes (without actually
making changes).
-e <templating engine>, --engine <templating engine>
templating engine: "handlebars"(default) or "mustache"
--enable-post-process-file
Enable post-processing file using environment variables.
-g <generator name>, --generator-name <generator name>
generator to use (see list command for list)
--git-host <git host>
Git host, e.g. gitlab.com.
--git-repo-id <git repo id>
Git repo ID, e.g. openapi-generator.
--git-user-id <git user id>
Git user ID, e.g. openapijsonschematools.
--global-property <global properties>
sets specified global properties (previously called 'system
properties') in the format of name=value,name=value (or multiple
options, each with name=value)
--group-id <group id>
groupId in generated pom.xml
--hide-generation-timestamp
Hides the generation timestamp when files are generated.
--http-user-agent <http user agent>
HTTP user agent, e.g. codegen_csharp_api_client, default to
'OpenAPI-Generator/{packageVersion}/{language}'
-i <spec file>, --input-spec <spec file>
location of the OpenAPI spec, as URL or file (required if not loaded
via config using -c)
--ignore-file-override <ignore file override location>
Specifies an override location for the .openapi-generator-ignore
file. Most useful on initial generation.
--ints-allowed-for-float-double-formats
Integers are allowed in for type: number format:float/double
payloads
--invoker-package <invoker package>
root package for generated code
--minimal-update
Only write output files that have changed.
--model-name-prefix <model name prefix>
Prefix that will be prepended to all model names.
--model-name-suffix <model name suffix>
Suffix that will be appended to all model names.
-o <output directory>, --output <output directory>
where to write the generated files (current dir by default)
-p <additional properties>, --additional-properties <additional
properties>
sets additional properties that can be referenced by the mustache
templates in the format of name=value,name=value. You can also have
multiple occurrences of this option.
--package-name <package name>
package for generated classes (where supported)
--release-note <release note>
Release note, default to 'Minor update'.
--remove-enum-value-prefix
Remove the common prefix of enum values
--remove-operation-id-prefix
Remove prefix of operationId, e.g. config_getId => getId
-s, --skip-overwrite
specifies if the existing files should be overwritten during the
generation.
--skip-operation-example
Skip examples defined in operations to avoid out of memory errors.
--skip-validate-spec
Skips the default behavior of validating an input specification.
--strict-spec <true/false strict behavior>
'MUST' and 'SHALL' wording in OpenAPI spec is strictly adhered to.
e.g. when false, no fixes will be applied to documents which pass
validation but don't follow the spec.
-t <template directory>, --template-dir <template directory>
folder containing the template files
-v, --verbose
verbose mode
然后,您可以使用自动生成的客户端。 readme.md是一个很好的起点。
其他发电机也有样品。
请参阅如何自定义输出(例如软件包名称,版本)的customization.md。
请参阅Integration.md,以了解如何将OpenAPI Generator与Maven,Gradle,Github和CI/CD集成。
OpenAPI JSON架构生成器项目旨在为Open API规范用户带来好处。该项目本身具有指定的许可证。此外,请了解以下几点:
当该项目生成代码时,应按照软件的用户视为并拥有该代码。没有保证(表达或暗示)生成的代码。您可以按照自己的意愿来完成您的意愿,并且一旦生成,代码就是您的责任,并且遵守您认为适当的许可条款。
GitHub代码搜索
此存储库基于OpenAPI Generator的v6.2.0。该项目着重于使输出100%符合JSON模式,作为OpenAPI 3.1规范的一部分,重点是复杂案例(自上而下的方法)。目的是完全支持JSON模式中定义的所有内容,以便开发人员可以在其API设计中利用JSON模式以及OpenAPI规范。在这里构建可以更快地支持OpenAPI 3.X中的新功能,而不必支持许多不使用新功能的较老的发电机。
OpenAPI JSON架构生成器基于OpenAPI Generator v6.2.0。该项目之所以创建,是因为OpenAPI-Generator Core团队需要从其项目中删除Python发电机。 Python Generator(@-Spacether)的作者更愿意继续在OpenAPI-Generator Repo中建造,但核心团队拒绝考虑将Python保留在OpenAPI-Generator中。以下是这些事件的时间表及其某些原因:
版权2023 OpenAPI-JSON-SCHEMA-GENERATOR贡献者版权所有2018 OpenAPI-Generator贡献者(https://openapi-generator.tech)版权所有2018 SmartBear Spart
根据Apache许可证(版本2.0(“许可”)获得许可;除了符合许可外,您不得使用此文件。您可以在apache.org/licenses/license-2.0获得许可证的副本
除非适用法律要求或以书面形式同意,否则根据许可证分配的软件是按照“原样”分发的,没有任何明示或暗示的任何形式的保证或条件。请参阅许可证,以获取执行许可条款和限制的特定语言。