Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to make all output properties readonly? #214

Open
craigmiller160 opened this issue Aug 20, 2023 · 5 comments
Open

Is there any way to make all output properties readonly? #214

craigmiller160 opened this issue Aug 20, 2023 · 5 comments

Comments

@craigmiller160
Copy link
Contributor

I'm a strong proponent of immutable data structures. I would love if there was some way that the schemas generated would have all properties set to readonly. I'm currently exploring the API of this library, and I don't see a way to do this yet. Hoping there is a solution, or that a new argument can be added to the CLI.

Thanks.

@astahmer
Copy link
Owner

maybe you could do it with a custom handlebars template ?

another simple way would be to traverse your OpenAPI schemas and add readonly on each properties before passing that OpenAPI document to openapi-zod-client

@craigmiller160
Copy link
Contributor Author

The documentation on how to use the custom handlebars template is far from ideal. I've been trying to figure it out for a minute, I haven't used handlebars very much but it seems simple enough. The big issue for me is understanding all the different context variables that are available and how to use them. Again, I don't see good documentation about this.

As for marking things as readonly in the OpenAPI schema, that is something I hadn't considered. I will investigate this option.

@craigmiller160
Copy link
Contributor Author

I'm not seeing any easy ways with handlebars to customize things to the point of making all types readonly. Customizing the openapi schema isn't always an option as well. I'm really hoping that this feature could be added in the future.

@astahmer
Copy link
Owner

Customizing the openapi schema isn't always an option as well.

what's the issue with your case ?

I'm really hoping that this feature could be added in the future.

feel free to send a PR 🙏

@craigmiller160
Copy link
Contributor Author

feel free to send a PR 🙏

Thanks for the invitation. Here is the PR adding the requested functionality: #221

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

No branches or pull requests

2 participants