Skip to content
Open
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ web_modules/
# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache
# Optional oxlint cache
.oxlintcache

# Microbundle cache
.rpt2_cache/
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
"recommendations": ["esbenp.prettier-vscode"]
}
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<br>
<br>
Tooling to give you full type-safety around OpenAPI specs.

</div>

<br>
Expand Down Expand Up @@ -205,9 +205,7 @@ the `@openapi-codegen/cli` supports these generator plugins:
generate all schema types for your specification:

```ts
const { schemasFiles } = await generateSchemaTypes(context, {
/* config */
});
const { schemasFiles } = await generateSchemaTypes(context, {/* config */});
```

output: `{namespace}Schemas.ts`
Expand Down
38 changes: 17 additions & 21 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,29 @@
"README.md"
],
"dependencies": {
"@clack/prompts": "^0.9.1",
"@octokit/request": "^9.2.2",
"@swc/core": "^1.2.118",
"@clack/prompts": "^1.8.1",
"@octokit/request": "^10.0.16",
"@swc/core": "^1.16.13",
"case": "^1.6.3",
"cli-highlight": "^2.1.11",
"clipanion": "^4.0.0-rc.4",
"fs-extra": "^10.0.0",
"got": "^12.0.0",
"got-fetch": "^5.1.1",
"js-yaml": "^4.1.0",
"openapi3-ts": "^4.4.0",
"prettier": "^3.2.5",
"slash": "^4.0.0",
"fs-extra": "^11.4.1",
"got": "^16.0.0",
"js-yaml": "^5.4.3",
"openapi3-ts": "^4.6.1",
"prettier": "^3.9.9",
"slash": "^5.1.0",
"swagger2openapi": "^7.0.8",
"tslib": "^2.3.1",
"tslib": "^2.8.1",
"typanion": "^3.14.0",
"typescript": "5.7.3"
"typescript": "~6.0.2"
},
"devDependencies": {
"@swc-node/register": "^1.4.0",
"@types/fs-extra": "^9.0.13",
"@types/js-yaml": "^4.0.3",
"@types/nock": "^11.1.0",
"@types/prettier": "^3.0.0",
"@types/slash": "^3.0.0",
"nock": "^13.2.1",
"react": "^18.3.1",
"tsup": "^8.3.5"
"@swc-node/register": "^1.12.1",
"@types/fs-extra": "^11.0.4",
"@types/js-yaml": "^4.0.9",
"nock": "^15.0.1",
"react": "^19.3.0",
"tsup": "^8.5.1"
}
}
32 changes: 18 additions & 14 deletions cli/src/commands/InitCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,21 @@ export class InitCommand extends Command {
message: "Relative path",
placeholder: "./openapi.json",
validate(value) {
if (!value.startsWith("./") && !value.startsWith("../"))
const input = typeof value === "string" ? value : "";

if (!input.startsWith("./") && !input.startsWith("../"))
return "The path should be relative";

if (
!value.endsWith(".json") &&
!value.endsWith(".yaml") &&
!value.endsWith(".yml")
!input.endsWith(".json") &&
!input.endsWith(".yaml") &&
!input.endsWith(".yml")
) {
return "The file must be a json or yaml";
}
},
})
.then(handlePromptCancel),
.then(handlePromptCancel<string>),
source: "file",
};
}
Expand All @@ -132,19 +134,21 @@ export class InitCommand extends Command {
message: "Url",
placeholder: "https://.../openapi.json",
validate(value) {
if (!value.startsWith("https://") && !value.startsWith("http://")) {
const input = typeof value === "string" ? value : "";

if (!input.startsWith("https://") && !input.startsWith("http://")) {
return "Url must starts with http or https protocol";
}
if (
!value.endsWith(".json") &&
!value.endsWith(".yaml") &&
!value.endsWith(".yml")
!input.endsWith(".json") &&
!input.endsWith(".yaml") &&
!input.endsWith(".yml")
) {
return "Url must ends with `.json` or `.yaml` or `.yml`";
}
},
})
.then(handlePromptCancel),
.then(handlePromptCancel<string>),
};
}

Expand All @@ -165,7 +169,7 @@ export class InitCommand extends Command {
],
message: "Select the source of your OpenAPI",
})
.then(handlePromptCancel);
.then(handlePromptCancel<"file" | "url">);

const from: FromOptions =
source === "file" ? await this.askForFile() : await this.askForUrl();
Expand All @@ -175,7 +179,7 @@ export class InitCommand extends Command {
.text({
message: "What namespace do you want for your API?",
})
.then(handlePromptCancel)
.then(handlePromptCancel<string>)
);

const plugin = await prompt
Expand All @@ -187,13 +191,13 @@ export class InitCommand extends Command {
{ label: "React Query components", value: "typescript/react-query" },
],
})
.then(handlePromptCancel);
.then(handlePromptCancel<Plugin>);

const outputDir = await prompt
.text({
message: "Which folder do you want to generate?",
})
.then(handlePromptCancel);
.then(handlePromptCancel<string>);

const configProperty = generateConfigProperty({
namespace,
Expand Down
4 changes: 1 addition & 3 deletions cli/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,4 @@ export type Import = {
};

export type Plugin =
| "typescript/types-only"
| "typescript/react-query"
| "typescript/fetch";
"typescript/types-only" | "typescript/react-query" | "typescript/fetch";
6 changes: 3 additions & 3 deletions cli/src/utils/getGithubToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { handlePromptCancel } from "./handlePromptCancel";
/**
* Ask for GitHub token if needed and save it for later.
*/
export async function getGithubToken() {
export async function getGithubToken(): Promise<string> {
const envToken = await getEnvGithubToken();
if (envToken) return envToken;

const token = await prompt
.text({
message: "Please provide a GitHub token with `repo` rules checked",
})
.then(handlePromptCancel);
.then(handlePromptCancel<string>);

await writeFile(githubTokenPath, token);

Expand All @@ -28,7 +28,7 @@ const githubTokenPath = join(homedir(), ".openapi-codegen");
/**
* Retrieve stored github token
*/
async function getEnvGithubToken() {
async function getEnvGithubToken(): Promise<string | undefined> {
let accessToken = process.env.GITHUB_TOKEN;
if (!accessToken && existsSync(githubTokenPath)) {
accessToken = await readFile(githubTokenPath, "utf-8");
Expand Down
5 changes: 3 additions & 2 deletions cli/src/utils/handlePromptCancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { isCancel, cancel } from "@clack/prompts";
* @param value Any value coming from a cancellable clark prompt
* @returns
*/
export async function handlePromptCancel<T>(value: T | symbol) {
export async function handlePromptCancel<T>(value: T | symbol): Promise<T> {
if (isCancel(value)) {
cancel("Operation cancelled! See you later 😁✌️");
process.exit(0);
}
return value;

return value as T;
}
3 changes: 0 additions & 3 deletions cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": "./"
},
"include": ["src/**/*"]
}
3 changes: 2 additions & 1 deletion cli/tsconfig.package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "lib"
"outDir": "lib",
"rootDir": "./src"
},
"files": ["src/index.ts"],
"include": ["src/types/**/*"]
Expand Down
27 changes: 0 additions & 27 deletions eslint.config.mjs

This file was deleted.

16 changes: 8 additions & 8 deletions examples/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
"gen:github": "openapi-codegen gen github"
},
"dependencies": {
"@tanstack/react-query": "5.66.0",
"react": "19.0.0",
"react-dom": "19.0.0"
"@tanstack/react-query": "5.104.1",
"react": "19.3.0",
"react-dom": "19.3.0"
},
"devDependencies": {
"@openapi-codegen/cli": "workspace:*",
"@openapi-codegen/typescript": "workspace:*",
"@types/react": "19.0.8",
"@types/react-dom": "19.0.3",
"@vitejs/plugin-react": "4.3.4",
"typescript": "5.7.3",
"vite": "6.0.11"
"@types/react": "19.3.0",
"@types/react-dom": "19.3.0",
"@vitejs/plugin-react": "6.1.2",
"typescript": "~6.0.2",
"vite": "8.3.3"
}
}
Loading
Loading