-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rust): revamp the OpenAPI specification (#1564)
The `agama-web-server docs` command generates the OpenAPI specification of Agama's HTTP API. However, the resulting specification is badly broken 😢. This pull request aims to make the specification usable. ## Refactoring Apart from being incomplete, the previous implementation had a few problems. * The code relies on [OpenApi proc-macro](https://docs.rs/utoipa/latest/utoipa/derive.OpenApi.html). This macro requires the data types to implement the [ToSchema trait](https://docs.rs/utoipa/latest/utoipa/trait.ToSchema.html), and due to the orphan rule, we cannot implement it for third-party types (e.g., `IpAddr`, `IpInet`, etc.). * We did not find a way to add the description of the common APIs (e.g., *progress* or *issues*) under each "scope". For those reasons, we decided to use the builder API, which is pretty flexible. We also took the chance to split the generation into smaller pieces, making it easier to maintain. ## Packaging the OpenAPI documentation Instead of generating the OpenAPI spec at runtime, we can do it at build time and put the resulting JSON files in a separate package (`agama-openapi`). ## Generating the `schema.d.ts` You can generate the API in two simple steps: ``` $ cargo run -p agama-server --bin agama-web-server openapi > openapi.json $ npx @hey-api/openapi-ts -i openapi.json -o src/client -c axios ``` ## To do * [x] Merging specifications is not the right approach because it does not detect conflicts (e.g., network and storage devices). Perhaps it might be a good idea to generate a separate specification for each scope (e.g., network). * [x] Add third-party types descriptions. * [x] Add validation to CI. ## Future work * Add the DASD API. * Add the common interfaces (e.g., *progress*, *issues*, etc.)
- Loading branch information
Showing
26 changed files
with
527 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ flate2 = "1.0.34" | |
chrono-tz = "0.8.6" | ||
regex = "1" | ||
thiserror = "1.0.64" | ||
utoipa = "4.2.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.