-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Send "types+transform" to hey-api-openapi-ts when useDateType is enabled #138
base: v1
Are you sure you want to change the base?
Conversation
After fiddeling around a bit, it does not look like a I added born:
type: string
format: date-time to pet and |
Is there some way to attach a debugger when generating code? |
By outputting the source map during the build with a command like {
"version": "0.2.0",
"configurations": [
{
"name": "Launch via npm",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}/examples/react-app",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"generate:api"
]
}
]
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR. It looks like a bit more work is needed.
@@ -36,7 +36,7 @@ export async function generate(options: LimitedUserConfig, version: string) { | |||
asClass: true, | |||
}, | |||
types: { | |||
dates: formattedOptions.useDateType, | |||
dates: formattedOptions.useDateType ? "types+transform" : false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type of the dates
option in @hey-api/openapi-ts
is boolean | 'types+transform' | 'types'
.
Therefore, instead of using a ternary operator here, I believe it would be more appropriate to adjust the type of LimitedUserConfig
.
An example of the command when executed via CLI should look as follows:
openapi-rq -i ./petstore.yaml --useDateType=types+transform
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cli.mts
will also look like the following.
#!/usr/bin/env node
import { readFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { Command, Option } from "commander";
import { defaultOutputPath } from "./constants.mjs";
import { generate } from "./generate.mjs";
const program = new Command();
export type LimitedUserConfig = {
input: string;
output: string;
client?: "angular" | "axios" | "fetch" | "node" | "xhr";
request?: string;
format?: "biome" | "prettier";
lint?: "biome" | "eslint";
operationId?: boolean;
serviceResponse?: "body" | "response";
base?: string;
enums?: "javascript" | "typescript" | "typescript+namespace";
useDateType?: boolean | "types+transform" | "types";
debug?: boolean;
noSchemas?: boolean;
schemaType?: "form" | "json";
pageParam: string;
nextPageParam: string;
};
const datesType: Extract<
LimitedUserConfig["useDateType"],
"types+transform" | "types"
>[] = ["types", "types+transform"];
async function setupProgram() {
// ...
program
.name("openapi-rq")
.version(version)
.description("Generate React Query code based on OpenAPI")
.requiredOption(
"-i, --input <value>",
"OpenAPI specification, can be a path, url or string content (required)"
)
// ...
.option(
"--useDateType [value]",
"Use Date type instead of string for date types for models. See https://heyapi.vercel.app/openapi-ts/transformers.html#dates",
(value) => {
if (value === undefined) {
return true;
}
if (value === "true" || value === "false") {
return value === "true";
}
if (datesType.includes(value as "types+transform" | "types")) {
return value;
}
throw new Error("Invalid value for useDateType");
},
false
)
// ...
.parse();
const options = program.opts<LimitedUserConfig>();
await generate(options, version);
}
Resolves: #137
I'm a bit unsure of how to test that it works correctly, do you have any idea´s?