Replies: 1 comment
-
Component names aren't always valid JS identifiers, so in order to support this there would need to be some level of mutation. I'm certain that whatever "default" mutation we were to select, it would not suit some end users, and allowing bespoke transformations means we would also need to handle de-duplication. In the meantime, you may generate your types normally, and then write a utility to create the mapping you want. import { components } from './generated-types.ts';
// Get a JS representation of the raw schema
const schema = fs.readFileSync('schema.json', 'utf-8');
const output = Object.keys(schema.components.schemas).map((key) =>
`export const ${schema} = components['schemas'][${JSON.stringify(schema)];`
).join('\n');
fs.writeFileSync('mapping.ts', output, 'utf-8'); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey all,
I noticed that the generated TypeScript code follows this structure:
To use a schema, I have to do:
I find this approach a bit cumbersome. Instead, it would be more convenient if the generator created TypeScript types directly, similar to how hey-api/openapi-ts does:
This way, I can use the types directly without having to reference them through ["schemas"]["component"]. Would it be possible to support this as an option?
Thanks! 🚀
Beta Was this translation helpful? Give feedback.
All reactions