Skip to content

Commit

Permalink
chore: Update CLI option to disable using operationId for generating …
Browse files Browse the repository at this point in the history
…operation names
  • Loading branch information
7nohe committed Oct 14, 2024
1 parent f65ac4e commit a8f2935
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/src/content/docs/guides/cli-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ The available options are:
- `biome`
- `eslint`

### --operationId
### --noOperationId

Use operation ID to generate operation names? The default value is `true`.
Do not use operation ID to generate operation names. The default value is `true`.

### --enums \<value\>

Expand Down
2 changes: 1 addition & 1 deletion examples/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dev:mock": "prism mock ../petstore.yaml --dynamic",
"build": "tsc && vite build",
"preview": "vite preview",
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../petstore.yaml --format=biome --lint=biome -c @hey-api/client-axios",
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../routes.json --format=biome --lint=biome -c @hey-api/client-axios",
"test:generated": "tsc -p ./tsconfig.json --noEmit"
},
"dependencies": {
Expand Down
148 changes: 148 additions & 0 deletions examples/routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"openapi": "3.0.3",
"info": {
"title": "api",
"description": "",
"license": {
"name": ""
},
"version": "0.0.0"
},
"paths": {
"/api/v1/boards/export": {
"get": {
"tags": ["boards"],
"summary": "Returns an export of a collection of boards.",
"operationId": "export",
"parameters": [
{
"name": "name",
"in": "query",
"description": "The name of the resultant file (including extension).",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "boards[]",
"in": "query",
"description": "The boards to be included in this export.",
"required": true,
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BoardId"
}
}
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
}
}
}
},
"/api/v1/documents/{file}/export": {
"get": {
"tags": ["documents"],
"summary": "Exports the document as a PDF with annotations included.",
"operationId": "export",
"parameters": [
{
"name": "file",
"in": "path",
"required": true,
"schema": {
"$ref": "#/components/schemas/FileId"
}
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/pdf": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
}
}
}
},
"/api/v1/tags/export": {
"get": {
"tags": ["tags"],
"summary": "Returns an export of a collection of tags.",
"operationId": "export",
"parameters": [
{
"name": "name",
"in": "query",
"description": "The name of the resultant file (including extension).",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "tags[]",
"in": "query",
"description": "The tags to be included in this export.",
"required": true,
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TagId"
}
}
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"BoardId": {
"type": "string",
"format": "base58 encoded UUID",
"example": "CBD7wDFfZFjQfkvZ5BfC9"
},
"FileId": {
"type": "string",
"format": "base58 encoded UUID",
"example": "CBD7wDFfZFjQfkvZ5BfC9"
},
"TagId": {
"type": "string",
"format": "base58 encoded UUID",
"example": "CBD7wDFfZFjQfkvZ5BfC9"
}
}
}
}
7 changes: 5 additions & 2 deletions src/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type LimitedUserConfig = {
client?: "@hey-api/client-fetch" | "@hey-api/client-axios";
format?: "biome" | "prettier";
lint?: "biome" | "eslint";
operationId?: boolean;
noOperationId?: boolean;
enums?: "javascript" | "typescript" | false;
useDateType?: boolean;
debug?: boolean;
Expand Down Expand Up @@ -58,7 +58,10 @@ async function setupProgram() {
"Process output folder with linter?",
).choices(["biome", "eslint"]),
)
.option("--operationId", "Use operation ID to generate operation names?")
.option(
"--noOperationId",
"Do not use operationId to generate operation names",
)
.addOption(
new Option(
"--enums <value>",
Expand Down
5 changes: 1 addition & 4 deletions src/generate.mts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ export async function generate(options: LimitedUserConfig, version: string) {
services: {
export: true,
asClass: false,
operationId:
formattedOptions.operationId !== undefined
? formattedOptions.operationId
: true,
operationId: !formattedOptions.noOperationId,
},
types: {
dates: formattedOptions.useDateType,
Expand Down

0 comments on commit a8f2935

Please sign in to comment.