swagger-codegenでAPIクライアントを生成するメモ
swagger-codegenとは
swagger-codegenとは、OpenAPIで書かれたAPI定義ファイルから、
APIクライアント(サーバスタブ)を生成するものです。
どんなコードが生成されるの? / 何の言語に対応してるの?
templateを見ましょう。
生成の仕方 (例: PHP)
1. インストール
https://github.com/swagger-api/swagger-codegen#compatibility
※ OpenAPIのバージョンに対応するバージョンをインストールしましょう。
2. 設定可能なconfigを確認し、jsonファイルで記述
確認
swagger-codegen config-help -l
php
記述
config.json
{
"modelPackage" : "Model",
"apiPackage" : "Api",
"variableNamingConvention" : "camelCase"
"artifactVersion" : "1.0.0",
"hideGenerationTimestamp" : "true"
}
3. 元テンプレートをカスタマイズ
templateで、自分の使う言語のものをローカルにコピー, カスタマイズしましょう。
4. 生成しましょう
swagger-codegen generate \
-l php \
-i ./your-swagger-file.yml \
-o ./ \
-c ./config.json \
-t ./templates
生成されたコードのライセンスについて
Generated code is intentionally not subject to the parent project license
When code is generated from this project, it shall be considered AS IS and owned by the user of the software.
とあるので、生成した本人のものになると理解しています。
Author And Source
この問題について(swagger-codegenでAPIクライアントを生成するメモ), 我々は、より多くの情報をここで見つけました https://qiita.com/wana4jp/items/2709a3b04a7f5331c85d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .