Giter Site home page Giter Site logo

openapi-to-locust's Introduction

openapi-to-locust

これは OpenAPI の定義から、Python で記述された Model ファイルと Api ファイルを自動生成するためのツールです
自動生成された成果物は、 Locust で使用することを想定して作成しています

使い方

基本的に Docker で動かすことを想定しています
Makefile にショートカットを定義してあるので、make コマンドを叩けると便利です

  1. make init をして、.envnode_modules を用意します
  2. .envopenapi.yaml のパスを(ファイル名を含めて)指定します
    1. openapi-generator-cli は相対パスを解釈できないので、openapi.yaml 1 ファイルに定義をすべてまとめた状態にする必要があります
  3. make generate-locust で Model ファイルと Api ファイルを自動生成します
    1. OpenAPI に example を網羅的に定義しているのであれば make generate-locust-example で example ファイルもまた自動生成できます
  4. ./dist/locust/api, ./dist/locust.model に成果物が格納されます
    1. ./example/util にあるファイルも使用することを想定しているので、一緒にコピーしてください
    2. コピーされた ./example/util にあったファイルは、プロジェクトの要求にあわせて書き換えられることを想定しています

妥協点

冗長な import

model モジュールにおいて、不要な import は消すことができたのですが、
重複して冗長になっている import を消すことができなかったので、残ってしまっています

なお model モジュールにおいては from model import * と指定することはできません
循環参照になってしまうためです

実装範囲

OpenAPI が表現できる定義すべてを変換できる、といったことは、いまのところ目指していません
このツールを作成する目的となったプロジェクトで、最低限動く程度までしか実装していません

もし動かない部分があったら issue や PR などを雑に投げてください

generator のバージョン

https://github.com/OpenAPITools/openapi-generator の最新 ( >= 6.2) を使いたかったのですが、
Unable to make field transient といったエラーを避けたいので、ひとまず 6.1.0 にしています
cf. OpenAPITools/openapi-generator#11763
cf. OpenAPITools/openapi-json-schema-generator#3

リテラルをラップしたオブジェクトの example

    WrappedObject:
      title: WrappedObject
      type: integer
      maximum: 2
      minimum: 1
      example: 1

上記のような定義をしたとき、mustache になぜか example が降ってきません

ですので、実行時エラーが発生するようなファイルが自動生成されてしまいますが、
ひとまず現時点では、逐一手動で直してもらうものとして妥協しています

コンテナについて

  • python3
    • 自動生成した Python のコードを整形するためのコンテナです
  • node
    • openapi-generator-cli を実行するためのコンテナです
  • locust
    • 開発用のもので、IDE のインタプリタとして指定するためのものです
      • ですので、このコンテナはビルドしておくだけで、コマンドの実行などは一切行いません

メモ

  • mustache ファイルに降ってくる変数を確認したいときは、{{{this}}} などとすると一通り dump されます
  • locust のプロジェクトにおいて、logging パッケージなどを使用すると、worker コンテナの標準出力に書き出されます

openapi-to-locust's People

Contributors

shztmk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.