Skip to content

Commit

Permalink
add generation of openapi.json, swith to openapi example in update.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
kilork committed Mar 23, 2024
1 parent 73b0582 commit c18d92d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ Example: official version `13.0.1` is `13.0.100` for crate version. `13.0.102` m
To update current version use provided [update.ts](./update.ts) `deno` script:

```sh
deno run --allow-env=KEYCLOAK_RUST_VERSION,KEYCLOAK_VERSION,KEYCLOAK_RUST_MAJOR_VERSION --allow-read=Cargo.toml --allow-write=Cargo.toml,docs/rest-api.html,src/types.rs,src/rest/generated_rest.rs --allow-net=keycloak.org,www.keycloak.org --allow-run=cargo,gh,git update.ts
deno run --allow-env=KEYCLOAK_RUST_VERSION,KEYCLOAK_VERSION,KEYCLOAK_RUST_MAJOR_VERSION --allow-read=Cargo.toml --allow-write=Cargo.toml,docs/rest-api.html,src/types.rs,src/rest/generated_rest.rs --allow-net=keycloak.org,www.keycloak.org --allow-run=cargo,docker,gh,git,handlebars-magic update.ts
```
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Example: official version `13.0.1` is `13.0.100` for crate version. `13.0.102` m
To update current version use provided [update.ts](./update.ts) `deno` script:
```sh
deno run --allow-env=KEYCLOAK_RUST_VERSION,KEYCLOAK_VERSION,KEYCLOAK_RUST_MAJOR_VERSION --allow-read=Cargo.toml --allow-write=Cargo.toml,docs/rest-api.html,src/types.rs,src/rest/generated_rest.rs --allow-net=keycloak.org,www.keycloak.org --allow-run=cargo,gh,git update.ts
deno run --allow-env=KEYCLOAK_RUST_VERSION,KEYCLOAK_VERSION,KEYCLOAK_RUST_MAJOR_VERSION --allow-read=Cargo.toml --allow-write=Cargo.toml,docs/rest-api.html,src/types.rs,src/rest/generated_rest.rs --allow-net=keycloak.org,www.keycloak.org --allow-run=cargo,docker,gh,git,handlebars-magic update.ts
```
*/
Expand All @@ -111,4 +111,4 @@ pub use error::KeycloakError;
pub use rest::{
KeycloakAdmin, KeycloakAdminToken, KeycloakServiceAccountAdminTokenRetriever,
KeycloakTokenSupplier,
};
};
2 changes: 1 addition & 1 deletion templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ Example: official version `13.0.1` is `13.0.100` for crate version. `13.0.102` m
To update current version use provided [update.ts](./update.ts) `deno` script:

```sh
deno run --allow-env=KEYCLOAK_RUST_VERSION,KEYCLOAK_VERSION,KEYCLOAK_RUST_MAJOR_VERSION --allow-read=Cargo.toml --allow-write=Cargo.toml,docs/rest-api.html,src/types.rs,src/rest/generated_rest.rs --allow-net=keycloak.org,www.keycloak.org --allow-run=cargo,gh,git update.ts
deno run --allow-env=KEYCLOAK_RUST_VERSION,KEYCLOAK_VERSION,KEYCLOAK_RUST_MAJOR_VERSION --allow-read=Cargo.toml --allow-write=Cargo.toml,docs/rest-api.html,src/types.rs,src/rest/generated_rest.rs --allow-net=keycloak.org,www.keycloak.org --allow-run=cargo,docker,gh,git,handlebars-magic update.ts
```
34 changes: 33 additions & 1 deletion update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Keycloak {
}
}

const EXAMPLE_FOR_GENERATION = "openapi";

class Cargo {
get text(): string {
return Deno.readTextFileSync("Cargo.toml");
Expand Down Expand Up @@ -108,7 +110,7 @@ class Cargo {
}

private async generate(kind: string): Promise<string> {
return await this.cargoCommand(["run", "--example", "gen", "--", kind]);
return await this.cargoCommand(["run", "--example", EXAMPLE_FOR_GENERATION, "--", kind]);
}

private async cargoCommand(args: string[]): Promise<string> {
Expand All @@ -120,6 +122,25 @@ class Cargo {
}
}

class Docker {
async generateOpenAPI(version: Version): Promise<void> {
return await this.dockerCommand([
"build",
"--build-arg",
`VERSION=${version}`,
"-o",
"docs",
"-f",
"docker/Dockerfile.docs",
"docker",
]);
}

private async dockerCommand(args: string[]): Promise<void> {
return await Command.spawn("docker", args);
}
}

class Branch {
readonly value: string;

Expand Down Expand Up @@ -292,6 +313,12 @@ class User {
type: Confirm,
default: true,
},
{
name: "generateOpenAPI",
message: `Generate openapi.json?`,
type: Confirm,
default: true,
},
{
name: "updateDocs",
message: `Update documentation?`,
Expand Down Expand Up @@ -708,6 +735,7 @@ class Updater {
readonly cargo: Cargo = new Cargo();
readonly git: Git = new Git("kilork/keycloak");
readonly keycloak: Keycloak = new Keycloak();
readonly docker: Docker = new Docker();
readonly user: User = new User();

options: Options = new Options();
Expand Down Expand Up @@ -760,6 +788,10 @@ class Updater {
Deno.writeTextFileSync("docs/rest-api.html", apiDocs);
}

if (options.generateOpenAPI) {
await this.docker.generateOpenAPI(milestoneVersion.toVersion());
}

if (options.updateDocs) {
await Command.spawn("handlebars-magic", ["templates", "."]);
}
Expand Down

0 comments on commit c18d92d

Please sign in to comment.