WIP - Experimentation to generate typescript client and server stubs#14
Closed
WIP - Experimentation to generate typescript client and server stubs#14
Conversation
Collaborator
Author
|
This PR should not be merged. I'm leaving it open here for a while in case anyone wants to review. I added a new wiki page to describe how to generate client SDKs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Experimentation with using code generators to create a Typescript Client (located in
src/cli/typescript) and server stubs (located insrc/srv/typescript).Refer to the README files in each of the above folders to review the steps take to produce the code.
Client
The client code and process to generate it are straight forward. The code looks reasonable. I haven't had a chance to do more than review it though. It was generated using the
openapi-generator-clithat @bitmotivator used to generate thegoclient.docker run --rm -v ${PWD}/:/local openapitools/openapi-generator-cli generate \ -i https://raw.githubusercontent.com/RDA-DMP-Common/common-madmp-api/refs/heads/init/openapi.yaml \ -g typescript \ -o /local/typescript \ --additional-properties=enumClassPrefix=true,generateInterfaces=true,supportDiscriminator=falseThere were some issues with the way it initially was using a default inheritance pattern that defined discriminators when they were not needed, so I added the
supportDiscriminator=falseargumentServer stubs
The
openapi-generator-clihad no suitable option for creating server stubs (to be fair the name has-cliin it so I figured it wouldn't solve this use case) so I had to look elsewhere.There are several offerings out there but all of them do not support (or fully support) openAPI v4.1.4 (v4.1.1 seems to be the highest supported). The ones I used below did not error out, they just threw warning that it was an unrecognized openAPI version.
I was able to use:
There are some issues with the Zod schema generation (at least in my local WebStorm IDE) that I need to track down.
More experimentation with other code generators would be useful for the server stubs, but I think we could come up with something reasonable that only requires a little bit of manual intervention. For example, Now that we have the Typescript types generated by
openapi-typescript, we may be able to find a generator that can use those instead to create Zod schemas and boilerplate express routes and middleware