Skip to content

WIP - Experimentation to generate typescript client and server stubs#14

Closed
briri wants to merge 1 commit intoinitfrom
typescript
Closed

WIP - Experimentation to generate typescript client and server stubs#14
briri wants to merge 1 commit intoinitfrom
typescript

Conversation

@briri
Copy link
Collaborator

@briri briri commented Jul 29, 2025

Experimentation with using code generators to create a Typescript Client (located in src/cli/typescript) and server stubs (located in src/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-cli that @bitmotivator used to generate the go client.

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=false

There 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=false argument

Server stubs

The openapi-generator-cli had no suitable option for creating server stubs (to be fair the name has -cli in 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:

  • openapi-typescript to generate Typescript types and interfaces from the OpenAPI schema file.
  • Orval to generate Zod schemas to assist with run-time parsing and validation of incoming maDMP JSON.
  • openapi-ts-router to manually create a stub Express router file that makes use of the above types and Zod schemas.

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

@briri
Copy link
Collaborator Author

briri commented Jul 30, 2025

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

@briri briri closed this Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant