This script automates the process of generating an OpenAPI client packaged as djangoflow_openapi
locally using a specified hostname and API version. Then we can override the remote djangoflow_openapi
with this local one to access our project specific models, endpoints etc. It uses the OpenAPI Generator to create a Dart client based on the provided or default parameters.
- Flutter installed (for running Flutter commands)
- Dart installed (for running Dart commands)
- OpenAPI Generator CLI installed (or set in the environment as OPENAPI_GENERATOR)
You can directly execute the script using the following curl | sh
command:
curl -sSL https://raw.githubusercontent.com/djangoflow/flutter-djangoflow/main/packages/djangoflow_openapi_extensions/tool/generate-openapi.sh | sh -s [hostname] [API_VERSION]
Replace [hostname]
with the base URL for the OpenAPI schema. If not provided, the script will default to http://127.0.0.1:8000
. Replace [API_VERSION]
with the version of the API. If not provided, it defaults to v1
.
To generate the OpenAPI client using a specific hostname and API version:
curl -sSL https://raw.githubusercontent.com/djangoflow/flutter-djangoflow/main/packages/djangoflow_openapi_extensions/tool/generate-openapi.sh | sh -s http://api.example.com:8000 v2
To use the default hostname and API version:
curl -sSL https://raw.githubusercontent.com/djangoflow/flutter-djangoflow/main/packages/djangoflow_openapi_extensions/tool/generate-openapi.sh | sh
- The script performs the following steps:
- Sets up required environment variables.
- Creates a target directory for the generated code.
- Uses OpenAPI Generator to generate Dart client code.
- Modifies generated code to fix an issue related to null fields.
- Upgrades Flutter packages.
- Runs Dart build runner to generate code.
- You can modify the default API version and other configuration options directly in the script.
- Make sure to have the required tools (Flutter, Dart, and OpenAPI Generator) installed and configured in your environment.
- It may not run
build_runner
due to dart-lang/pub#3978, to resolve it please navigate toYOUR_DIR/packages/djangoflow_openapi
and rundart run build_runner build
.