OpenAPI JSONスキーマジェネレーターを使用して、OpenAPI 3.0.0-3.1.0ドキュメントからクライアントSDKを自動生成します。このプロジェクトは、すべてのOpenAPIおよびJSONスキーマ機能のサポートに焦点を当てたコードジェネレーターです。
Openapi JSONスキーマジェネレーターは、Openapiドキュメント(3.0.0-3.1.0*がサポートされている)を考慮して、APIクライアントライブラリ(SDK生成)の自動生成を可能にします。このプロジェクトは、OpenAPI + JSONスキーマ仕様に100%準拠することに焦点を当てています。目標は、開発者がこれらすべての機能を使用できるように、Openapi +含まれているJSONスキーマ仕様で定義されているすべてを完全にサポートすることです。
現在、次の言語/フレームワークがサポートされています。
| 特徴 | Python | Java | コトリン |
|---|---|---|---|
| ジェネレーターステータス | 安定した | 安定した | 安定した |
| Openapi v3.0.0-3.1.0摂取 | x | x | x |
| JSONスキーマ2020-12サポート(コンポーネント/スキーマ) | x | x | x |
| コンポーネントスキーマクラス +ドキュメントが作成されました | x | x | x |
| 他のコンポーネントタイプ用に作成されたドキュメント: ヘッダー、パラメーター、リクエストボディ、レスポンズ、セキュリティスキーム | x | x | |
| エンドポイント用に生成された方法 それらのために生成されたJSON +ドキュメントを送信/受信します | x | x |
1var 、 hi-thereなどのfromにサポートされていますDiscordサーバーを場所として使用して、質問をしたり、お互いに支援したりします。 Slackに非常によく似た機能を提供します。 https://discord.gg/mhb8wequyqでご参加ください
はい;貢献は大歓迎です!新しいサーバーの足場、クライアントSDK、またはドキュメントジェネレーターを任意の言語に追加する場合は、PRを送信します。
Openapi仕様は、2010年の最初の作成以来3回の改訂を受けています。Openapi-Json-Schema-Generator Projectには、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 (eg /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クリーンインストール-Uコマンドを実行するだけです。
org.apache.maven.lifecycle.lifecycleexecutionexception:目標org.apache.maven.plugins:maven-surefire-plugin:2.19.1:Project Openapi-json-schema-generatorでのテスト(デフォルトテスト):実行中のタイプの非互換性が発生しました。 org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test:java.lang.exceptioninitializererrorはjava.io.ioexceptionにキャストできません
./run-in-docker.sh mvn clean install -U目標org.fortasoft:gradle-maven-plugin:1.0.8:Project Openapi-JSON-Schema-Generator-Gradle-Plugin-Mvn-Wrapper:org.gradle.tooling.buildexceptionでInvoke(デフォルト)を呼び出してください:Gradle Distributionを使用してビルドを実行できません'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
次のように、ペットストア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は良い出発点です。
他のジェネレーターにもサンプルがあります。
出力をカスタマイズする方法については、カスタマイズを参照してください(例:パッケージ名、バージョン)
OpenapiジェネレーターをMaven、Gradle、Github、Ci/CDと統合する方法については、Integration.mdを参照してください。
Openapi JSONスキーマジェネレータープロジェクトは、オープンAPI仕様のユーザーにとって利点として意図されています。プロジェクト自体には、指定されたライセンスがあります。さらに、次の点を理解してください。
このプロジェクトからコードが生成される場合、ソフトウェアのユーザーが所有していると見なされ、所有されます。生成されたコードに対して、保証はありません。あなたはそれで望むことをすることができ、一度生成されると、コードはあなたの責任であり、あなたが適切と思われるライセンス条件の対象となります。
GitHubコード検索
このレポは、OpenapiジェネレーターのV6.2.0に基づいています。このプロジェクトは、複雑なケース(トップダウンアプローチ)に焦点を当てたOpenapi 3.1仕様の一部として、JSONスキーマに100%準拠することに焦点を当てています(トップダウンアプローチ)。目標は、JSONスキーマで定義されているすべてを完全にサポートして、開発者がJSONスキーマとAPI設計のOpenAPI仕様を活用できるようにすることです。ここに構築することで、新機能を使用しない多くの古いジェネレーターをサポートすることなく、Openapi 3.xの新機能をサポートするより迅速な進歩が可能になります。
Openapi JSONスキーマジェネレーターは、Openapiジェネレーターv6.2.0に基づいています。このプロジェクトは、Openapi-Generator CoreチームがプロジェクトからPythonジェネレーターを削除する必要があるため、ここで作成されました。 Pythonジェネレーターの著者(@spacether)は、Openapi-Generator Repoに構築を続けることを好みましたが、CoreチームはPythonをOpenapi-Generatorに維持することを検討することを拒否しました。以下は、これらのイベントのタイムラインとその理由のいくつかです。
Copyright 2023 Openapi-Json-Schema-Generator Contributors Copyright 2018 Openapi-Generator Contributors(https://openapi-generator.tech)Copyright 2018 SmartBearソフトウェア
Apacheライセンス、バージョン2.0(「ライセンス」)に基づいてライセンスされています。ライセンスに準拠している場合を除き、このファイルを使用することはできません。 apache.org/licenses/license-2.0でライセンスのコピーを入手できます。
適用法で要求されていないか、書面で合意されていない限り、ライセンスに基づいて配布されたソフトウェアは、明示または黙示のいずれかの保証または条件なしに、「現状のまま」に基づいて配布されます。ライセンスに基づく権限と制限を管理する特定の言語のライセンスを参照してください。