Skip to content
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
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ Usage: openapi-rq [options]
Generate React Query code based on OpenAPI

Options:
-V, --version output the version number
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
-o, --output <value> Output directory (default: "openapi")
-c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
--useUnionTypes Use union types (default: false)
--exportSchemas <value> Write schemas to disk (default: false)
--indent <value> Indentation options [4, 2, tabs] (default: "4")
--postfix <value> Service name postfix (default: "Service")
--request <value> Path to custom request file
-h, --help display help for command
-V, --version output the version number
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
-o, --output <value> Output directory (default: "openapi")
-c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
--useUnionTypes Use union types (default: false)
--exportSchemas <value> Write schemas to disk (default: false)
--indent <value> Indentation options [4, 2, tabs] (default: "4")
--postfixServices <value> Service name postfix (default: "Service")
--postfixModels <value> Modal name postfix
--request <value> Path to custom request file
-h, --help display help for command
```

## Example Usage
Expand Down
8 changes: 4 additions & 4 deletions examples/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
"dev:mock": "prism mock ./petstore.yaml",
"build": "tsc && vite build",
"preview": "vite preview",
"generate:api": "node ../../dist/src/cli.js -i ./petstore.yaml -c axios --exportSchemas=true --postfix=Client --request ./request.ts",
"generate:api": "node ../../dist/src/cli.js -i ./petstore.yaml -c axios --exportSchemas=true --postfixServices=Client --request ./request.ts",
"test:generated": "tsc ./openapi/queries/index.ts --noEmit --target esnext --moduleResolution node"
},
"dependencies": {
"@tanstack/react-query": "^4.28.0",
"@tanstack/react-query": "^4.29.1",
"axios": "^1.3.5",
"form-data": "~4.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@stoplight/prism-cli": "^4.11.1",
"@types/react": "^18.0.33",
"@types/react": "^18.0.34",
"@types/react-dom": "^18.0.11",
"@vitejs/plugin-react": "^3.1.0",
"npm-run-all": "^4.1.5",
"typescript": "^5.0.3",
"typescript": "^5.0.4",
"vite": "^4.2.1"
}
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
"devDependencies": {
"@types/node": "^18.15.11",
"commander": "^10.0.0",
"glob": "^9.3.4",
"openapi-typescript-codegen": "^0.23.0",
"typescript": "^5.0.3"
"glob": "^10.0.0",
"openapi-typescript-codegen": "^0.24.0",
"typescript": "^5.0.4"
},
"peerDependencies": {
"commander": "> 10",
"glob": "> 9",
"openapi-typescript-codegen": "^0.23.0",
"commander": ">= 10 < 11",
"glob": ">= 10",
"openapi-typescript-codegen": "^0.24.0",
"typescript": ">= 4.8.3"
}
}
107 changes: 51 additions & 56 deletions pnpm-lock.yaml

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

5 changes: 3 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Options } from "openapi-typescript-codegen";
export type CLIOptions = {
output?: string;
client?: Options["httpClient"];
} & Pick<Options, 'exportSchemas' | 'postfix' | 'request' | 'indent' | 'input' | 'useUnionTypes'>;
} & Pick<Options, 'exportSchemas' | 'postfixModels' | 'postfixServices' | 'request' | 'indent' | 'input' | 'useUnionTypes'>;

const program = new Command();

Expand All @@ -28,7 +28,8 @@ program
.option("--useUnionTypes", "Use union types", false)
.option("--exportSchemas <value>", "Write schemas to disk", false)
.option("--indent <value>", "Indentation options [4, 2, tabs]", "4")
.option("--postfix <value>", "Service name postfix", "Service")
.option("--postfixServices <value>", "Service name postfix", "Service")
.option("--postfixModels <value>", "Modal name postfix")
.option("--request <value>", "Path to custom request file")
.parse();

Expand Down
4 changes: 2 additions & 2 deletions src/createExports.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ts from "typescript";
import glob from "glob";
import { sync } from "glob";
import { join } from "path";
import fs from "fs";
import { createUseQuery } from "./createUseQuery";
import { createUseMutation } from "./createUseMutation";

export const createExports = (generatedClientsPath: string) => {
const services = glob.sync(join(generatedClientsPath, 'services', '*.ts').replace(/\\/g, '/'));
const services = sync(join(generatedClientsPath, 'services', '*.ts').replace(/\\/g, '/'));
const nodes = services.map((servicePath) =>
ts.createSourceFile(
servicePath, // fileName
Expand Down
6 changes: 3 additions & 3 deletions src/createImports.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ts from "typescript";
import glob from "glob";
import { sync } from "glob";
import { extname, basename, join } from "path";

export const createImports = (generatedClientsPath: string) => {
const models = glob.sync(join(generatedClientsPath, 'models', '*.ts').replace(/\\/g, '/'));
const services = glob.sync(join(generatedClientsPath, 'services', '*.ts').replace(/\\/g, '/'));
const models = sync(join(generatedClientsPath, 'models', '*.ts').replace(/\\/g, '/'));
const services = sync(join(generatedClientsPath, 'services', '*.ts').replace(/\\/g, '/'));
return [
ts.factory.createImportDeclaration(
undefined,
Expand Down