This project uses Redocly and OpenAPI Generator to manage API documentation and generate client (TypeScript using fetch API) / server (Spring Boot) code with the help of OpenAPI Generator CLI.
Prior to codegen using node as a backend, stub generation was a part within the Gradle build system for the devstream-core
repository. For a detailed guide about code generation using Gradle, consider referencing Sam's Programming Notes, which explores how to integrate codegen with Gradle.
In case you need to run swagger documentation inside a container, you can build the openapi json file and run the following command to start swagger documentation in port 8002.
npm run openapi:rebuild-docs
podman run \
-p 8002:8080 \
-e SWAGGER_JSON=/openapi-specs/openapi.json \
-v ./build/docs/html:/openapi-specs \
swaggerapi/swagger-ui
Reference Dockerfile for swaggerapi/swagger-ui
The following npm scripts are available for working with the OpenAPI specification after installing required packages with npm ci
:
npm run get-version
: Prints the current version frompackage.json
.npm run openapi:lint
: Lints the bundled OpenAPI specification (./build/devstream.yml
) using Redocly and outputs results in a codeframe format.npm run openapi:build
: Bundles the OpenAPI specification (openapi.yml
) into a single YAML file (./build/devstream.yml
). This is required before other OpenAPI-related tasks.npm run openapi:build-json
: Bundles the OpenAPI specification (openapi.yml
) into a single JSON file (./build/devstream.json
).npm run openapi:preview
: Starts a local preview server for the OpenAPI documentation using Redocly.npm run openapi:validate
: Validates the bundled OpenAPI specification (./build/devstream.yml
) using OpenAPI Generator CLI with recommendations.npm run openapi:mint
: Runs the build, lint, and validate steps sequentially to ensure the specification is valid before generating code (npm run openapi:build && npm run openapi:build-json && npm run openapi:lint && npm run openapi:validate
). The build step produces both JSON and YAML specifications.npm run openapi:generate-server
: Generates server-side code (Spring) using OpenAPI Generator CLI and the configuration file./config/config-server.yml
. It sets the artifact version using the npm package version.npm run openapi:generate-client
: Generates client-side code (TypeScript Axios) using OpenAPI Generator CLI and the configuration file./config/config-client.yml
. It sets the npm version using the npm package version.npm run openapi:client-dist
: Changes directory to./build/client/typescript
, installs npm dependencies, and builds the client (cd ./build/client/typescript && npm install && npm run build
).npm run openapi:docs
: Generates API documentation using OpenAPI Generator CLI and outputs it to./docs
.npm run openapi:cpp-pistache-server
: Generates C++ Pistache server code using OpenAPI Generator CLI and outputs it to./build/server/pistache
.npm run openapi:go
: Generates Go server code using OpenAPI Generator CLI and the configuration file./config/config-go.yml
. It sets the package version using the npm package version.npm run openapi:python-fastapi
: Generates Python FastAPI server code using OpenAPI Generator CLI and outputs it to./build/server/fastapi
.npm run openapi:python-flask
: Generates Python Flask server code using OpenAPI Generator CLI and outputs it to./build/server/flask
.npm run openapi:aspnetcore
: Generates ASP.NET Core code using OpenAPI Generator CLI and the configuration file./config/config-aspnetcore.yml
. It sets the package version using the npm package version.npm run openapi:node-express
: Generates Node.js Express server code using OpenAPI Generator CLI and outputs it to./build/server/express
.npm run openapi:stubs
: Generates both server and client code (npm run openapi:generate-server && npm run openapi:generate-client
).npm run openapi:rebuild-stubs
: Runs the full OpenAPI workflow (build, lint, validate, generate server, generate client) (npm run openapi:mint && npm run openapi:stubs
).npm run openapi:rebuild-docs
: Runs the full OpenAPI workflow (build, lint, validate, generate docs) (npm run openapi:mint && npm run openapi:docs
).npm run prepare
: Installs husky for git hooks (husky install
). This typically runs automatically after firstnpm install
.
ogen.ps1
is used to generate the golang server stub with ogen. This uses podman to run the build step inside a container. Generated outputs are mapped to host computer using volumes. The configuration can be found in./config/ogen.yml
.
- vuejs/vitepress#3057: the vitepress base url is set to
/client
in thepackage.json
file to serve static assets, in case in future, we plan to serve the client document from some other route via changing the folder to which the generated docs are uploaded in thedevstream-docs
repository, we will also need to change the base route for vitepress.