nfroidure / nfroidure/schema2dts
Allow partial generation
@nfroidure is already working on this.
Since Dec 11, 2024.
- Dominant language
- TypeScript
- Stars
- 7
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
In the context of a framework, generating the whole schema types in a single pass and to a single file is not always suitable.
The best would be to allow to build partial schema based on some rules and a context.
For example, we could generate an API endpoint schema only for a single Whook's handler:
https://github.com/nfroidure/whook/blob/1cc395665c5c69e38d4f36612b16d5fc3dd92e72/packages/whook-example/src/handlers/putEcho.ts#L12-L111
Here we would export a src/handlers/putEcho.d.ts file containing the types for the schemas and the operation.
References to external schema could be imported or generated where they actually live and rebuild only when their contents change (via the watch function).
We will need a service that take the various file path for each generated schema (to compute imports) or the recipe to compute them. Also, the first run will probably need to generate the whole schema
The API interface could be something like:
type TypeGeneratorService = {
generateSchemas: (names: strings[]) => { path: string, contents: string }[];
generateOpenAPISchema: (content: string) => { path: string, contents: string }[];
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.