Send "types+transform" to hey-api-openapi-ts when useDateType is enabled#138
Send "types+transform" to hey-api-openapi-ts when useDateType is enabled#138AnderssonPeter wants to merge 1 commit into7nohe:v1from
Conversation
|
After fiddeling around a bit, it does not look like a I added born:
type: string
format: date-timeto 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"
]
}
]
} |
7nohe
left a comment
There was a problem hiding this comment.
Thank you for the PR. It looks like a bit more work is needed.
| }, | ||
| types: { | ||
| dates: formattedOptions.useDateType, | ||
| dates: formattedOptions.useDateType ? "types+transform" : false, |
There was a problem hiding this comment.
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+transformThere was a problem hiding this comment.
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);
}|
What is the status of this PR? is there anyway to add the date transformers in the current codegen version? |
|
@7nohe I have tried your suggestions above, but sadly no transformation code is generated. So something must be missing as just setting FYI: @maniator |
Resolves: #137
I'm a bit unsure of how to test that it works correctly, do you have any idea´s?