astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)
openapi-zod-client.vercel.app
795 stars 84 forks source link

Allow overriding each of endpointDefinition with a callback function #173

Closed imballinst closed 1 year ago

imballinst commented 1 year ago

Hello, thanks for creating this library!

I want to request to add 2 new fields here: operationId and security, because these 2 fields can exist in the Operation object.

https://github.com/astahmer/openapi-zod-client/blob/8fdb58f7a301610ba1d0ed5c63a35663e411b7fa/lib/src/getZodiosEndpointDefinitionList.ts#L154-L163

It's either that, or make us able to pass a callback function, something like:

endpointDefinitionRefiner: (defaultDefinition: EndpointDefinitionWithRefs, operation: OperationObject) => ({
  ...defaultDefinition,
  security: operation.security,
  operationId: operation.operationId
})

So the thing above becomes:

  const defaultDefinition: EndpointDefinitionWithRefs = { 
     method: method as EndpointDefinitionWithRefs["method"], 
     path: replaceHyphenatedPath(path), 
     ...(options?.withAlias && { alias: operationName }), 
     description: operation.description, 
     requestFormat: "json", 
     parameters: [], 
     errors: [], 
     response: "", 
  }
  const endpointDefinition = endpointDefinitionRefiner ? endpointDefinitionRefiner(defaultDefinition) : defaultDefinition 

I can submit a PR as well, if possible.

astahmer commented 1 year ago

I suppose you're not using zodios; and are only using openapi-zod-client to convert to zod schemas ? I like the callback version as it looks more future-proof

I can submit a PR as well, if possible.

go for it ! Don't forget to add a dedicated test + a changeset

imballinst commented 1 year ago

I suppose you're not using zodios; and are only using openapi-zod-client to convert to zod schemas ?

That is correct, yeah. I want to generate the boilerplates with koa and hence I can't use the zodios one.

I like the callback version as it looks more future-proof go for it ! Don't forget to add a dedicated test + a changeset

Alright, I'll see what I can do, thanks @astahmer for the quick response!