Skip to content

Commit

Permalink
refactor: switch openapi generator (#38)
Browse files Browse the repository at this point in the history
Switching to openapi-generator.tech generator instead of progenitor since has support for multiple return types
  • Loading branch information
hougesen authored Oct 13, 2024
1 parent e415134 commit cf34321
Show file tree
Hide file tree
Showing 61 changed files with 3,788 additions and 4,452 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### Unreleased

- refactor: codegen web api [`#37`](https://github.com/i18nhero/cli/pull/37)
- fix(push): create folder if not exists [`#36`](https://github.com/i18nhero/cli/pull/36)
- refactor: move generator to api [`#35`](https://github.com/i18nhero/cli/pull/35)
- build(deps): bump reqwest from 0.12.7 to 0.12.8 [`#34`](https://github.com/i18nhero/cli/pull/34)
Expand Down
67 changes: 13 additions & 54 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ clap_complete = "4.5.29"
console = { version = "0.15.8" }
dialoguer = { version = "0.11.0" }
dirs = { version = "5.0.1" }
futures-core = "0.3.31"
progenitor-client = "0.8.0"
reqwest = { version = "0.12.8", default-features = false, features = [
"brotli",
"charset",
Expand All @@ -39,11 +37,12 @@ reqwest = { version = "0.12.8", default-features = false, features = [
schemars = "0.8.21"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
serde_urlencoded = "0.7.1"
serde_repr = "0.1.19"
supports-hyperlinks = "3.0.0"
tempfile = "3.13.0"
terminal-link = "0.1.0"
tokio = { version = "1.40.0", features = ["full"] }
url = "2.5.2"
uuid = { version = "1.10.0", features = ["v4"] }

# Config for 'cargo dist'
Expand Down
29 changes: 15 additions & 14 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,29 @@ changelog:
npx auto-changelog -u

generate-web-api:
wget https://web.api.i18nhero.com/docs-json -O web.api.i18nhero.spec.json
cargo progenitor -i web.api.i18nhero.spec.json -o web-api -n web-api -v 0.0.0
rm -rf web_api
npx @openapitools/openapi-generator-cli generate -g rust -o web_api -i https://web.api.i18nhero.com/docs-json --global-property=modelDocs=false,apiDocs=false
find ./web_api -type f -exec sed -i 's/crate::/crate::codegen::web_api::/g' {} \;
mkdir -p packages/i18nhero/src/codegen/web_api
rm -rf packages/i18nhero/src/codegen/web_api
mv web-api/src/lib.rs web-api/src/mod.rs
mv web-api/src packages/i18nhero/src/codegen/web_api
rm -rf web-api
just format
mv web_api/src/lib.rs web_api/src/mod.rs
mv web_api/src packages/i18nhero/src/codegen/web_api
rm -rf web_api
cargo fmt

generate-cli-api:
wget https://cli.api.i18nhero.com/spec -O cli.api.i18nhero.spec.json
cargo progenitor -i cli.api.i18nhero.spec.json -o cli-api -n cli-api -v 0.0.0
rm -rf cli_api
npx @openapitools/openapi-generator-cli generate -g rust -o cli_api -i https://cli.api.i18nhero.com/spec --global-property=modelDocs=false,apiDocs=false
find ./cli_api -type f -exec sed -i 's/crate::/crate::codegen::cli_api::/g' {} \;
mkdir -p packages/i18nhero/src/codegen/cli_api
rm -rf packages/i18nhero/src/codegen/cli_api
mv cli-api/src/lib.rs cli-api/src/mod.rs
mv cli-api/src packages/i18nhero/src/codegen/cli_api
rm -rf cli-api
just format
mv cli_api/src/lib.rs cli_api/src/mod.rs
mv cli_api/src packages/i18nhero/src/codegen/cli_api
rm -rf cli_api
cargo fmt

precommit:
# will fail once progenitor adds support for multiple response types
! just generate-cli-api
# just generate-cli-api
just generate-web-api
just changelog
cargo clean
Expand Down
7 changes: 7 additions & 0 deletions openapitools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "7.9.0"
}
}
33 changes: 16 additions & 17 deletions packages/i18nhero/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,22 @@ default = []
json-schema = ["dep:schemars"]

[dependencies]
bytes = { workspace = true }
clap = { workspace = true }
clap_complete = { workspace = true }
console = { workspace = true }
dialoguer = { workspace = true }
dirs = { workspace = true }
futures-core = { workspace = true }
progenitor-client = { workspace = true }
reqwest = { workspace = true }
bytes.workspace = true
clap.workspace = true
clap_complete.workspace = true
console.workspace = true
dialoguer.workspace = true
dirs.workspace = true
reqwest.workspace = true
schemars = { workspace = true, optional = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_urlencoded = { workspace = true }
supports-hyperlinks = { workspace = true }
terminal-link = { workspace = true }
tokio = { workspace = true }
uuid = { workspace = true }
serde.workspace = true
serde_json.workspace = true
serde_repr.workspace = true
supports-hyperlinks.workspace = true
terminal-link.workspace = true
tokio.workspace = true
url.workspace = true
uuid.workspace = true

[dev-dependencies]
tempfile = { workspace = true }
tempfile.workspace = true
Loading

0 comments on commit cf34321

Please sign in to comment.