Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: codegen web api #37

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### Unreleased

- 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)
- build(deps): bump tempfile from 3.12.0 to 3.13.0 [`#33`](https://github.com/i18nhero/cli/pull/33)
- refactor: change DEFAULT_API_HOST to api.cli.i18nhero.com [`#32`](https://github.com/i18nhero/cli/pull/32)
Expand Down
61 changes: 58 additions & 3 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ readme = "README.md"
categories = ["command-line-utilities", "development-tools"]

[workspace.dependencies]
bytes = "1.7.2"
clap = { version = "4.5.18", features = ["derive"] }
clap_complete = "4.5.29"
console = { version = "0.15.8" }
dirs = { version = "5.0.1" }
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 @@ -36,6 +39,7 @@ 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"
supports-hyperlinks = "3.0.0"
tempfile = "3.13.0"
terminal-link = "0.1.0"
Expand Down
191 changes: 191 additions & 0 deletions cli.api.i18nhero.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
{
"openapi": "3.0.0",
"info": {
"title": "@i18nhero/public-api",
"version": "0.0.0"
},
"servers": [
{
"url": "https://api.i18nhero.com"
}
],
"tags": [],
"paths": {
"/organizations": {
"get": {
"responses": {
"200": {
"description": "",
"content": {
"application/json; charset=utf-8": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Organization"
}
}
}
}
},
"401": {
"description": "",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/PersonalAccessTokenNotFoundError"
}
}
}
},
"500": {
"description": "",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/DatabaseError"
}
}
}
}
},
"security": [
{
"ApiKeyAuth": []
}
],
"operationId": "get_organizations"
}
},
"/organizations/{organization_id}/projects": {
"get": {
"parameters": [
{
"name": "organization_id",
"schema": {
"type": "string",
"format": "oid"
},
"in": "path",
"required": true,
"deprecated": false,
"explode": true
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/json; charset=utf-8": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Project"
}
}
}
}
},
"401": {
"description": "",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/PersonalAccessTokenNotFoundError"
}
}
}
},
"403": {
"description": "",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/ForbiddenError"
}
}
}
},
"500": {
"description": "",
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/DatabaseError"
}
}
}
}
},
"security": [
{
"ApiKeyAuth": []
}
],
"operationId": "get_organization_projects"
}
}
},
"components": {
"schemas": {
"DatabaseError": {
"type": "object",
"required": ["message"],
"properties": {
"message": {
"type": "string"
}
}
},
"ForbiddenError": {
"type": "object",
"required": ["message"],
"properties": {
"message": {
"type": "string"
}
}
},
"Organization": {
"type": "object",
"required": ["_id", "title"],
"properties": {
"_id": {
"type": "string"
},
"title": {
"type": "string"
}
}
},
"PersonalAccessTokenNotFoundError": {
"type": "object",
"required": ["message"],
"properties": {
"message": {
"type": "string"
}
}
},
"Project": {
"type": "object",
"required": ["_id", "title"],
"properties": {
"_id": {
"type": "string"
},
"title": {
"type": "string"
}
}
}
},
"securitySchemes": {
"ApiKeyAuth": {
"type": "apiKey",
"description": "ApiKey authorization",
"name": "X-API-Key",
"in": "header"
}
}
}
}
23 changes: 23 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,30 @@ test-coverage:
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
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

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
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

precommit:
# will fail once progenitor adds support for multiple response types
! just generate-cli-api
just generate-web-api
just changelog
cargo clean
cargo dist init --yes
Expand Down
Loading