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

Enhancement: option to generate static type based on the runtype #28

Closed
haradzienski opened this issue Apr 9, 2021 · 8 comments · Fixed by #30
Closed

Enhancement: option to generate static type based on the runtype #28

haradzienski opened this issue Apr 9, 2021 · 8 comments · Fixed by #30

Comments

@haradzienski
Copy link
Contributor

Hi there! ✋

First of all, thank you for such a wonderful library - I've played with version 2.0.0-alpha-3 a bit, and it's awesome!

I am using the lib to generate runtypes based on an OpenAPI v2 (Swagger) spec, and I think it would be nice if there was an option to generate a static type (type Something = rt.Static<typeof something>;) based on the root type. I think it could work similar to how export flag currently works. I checked out the code, and looks like it could be as easy as adding one more conditionalWrite to this function: https://github.com/cobraz/generate-runtypes/blob/develop/src/main.ts#L84-L89.

I could make a PR if that's something you'd be willing to pull in.

Looking forward to hearing from you, and thanks again!

@haradzienski haradzienski changed the title Enahncement: option to generate static type based on the runtype Enhancement: option to generate static type based on the runtype Apr 9, 2021
@runeh
Copy link
Collaborator

runeh commented Apr 9, 2021

Sounds totally reasonable to me to support this.

@runeh
Copy link
Collaborator

runeh commented Apr 9, 2021

Should be a fairly small change. Might need to propagate some options to the various writers, but that should be straight-forward.

@runeh
Copy link
Collaborator

runeh commented Apr 9, 2021

I tried this out. Almost no code, so that's good 👍 See PR.

One issue here, what to do about naming? have the runtype name be lowercase and the type name be uppercase?

Should it be configurable? We could support a callback for creating the names I suppose, for anyone that wants something else than the default.

Should the default be to create types or not?

Thoughts @haradzienski @cobraz ?

@simenandre
Copy link
Owner

I am using the lib to generate runtypes based on an OpenAPI v2 (Swagger) spec

@haradzienski I would love to help out with that! It has been a wish for quite some time to build a tool that can do just that. I've currently only written some documentation/planning: https://gist.github.com/cobraz/a0031905833bc58d233451fe537f3019

I'm pretty sure there are lots of people who wants that to help :)

@simenandre
Copy link
Owner

simenandre commented Apr 9, 2021

One issue here, what to do about naming? have the runtype name be lowercase and the type name be uppercase?

I like the lower/upper-case version!

Should it be configurable? We could support a callback for creating the names I suppose, for anyone that wants something else than the default.

Probably a good thing!

Should the default be to create types or not?

We should probably create it by default!

@runeh
Copy link
Collaborator

runeh commented Apr 9, 2021

Updated

@haradzienski
Copy link
Contributor Author

@haradzienski I would love to help out with that! It has been a wish for quite some time to build a tool that can do just that. I've currently only written some documentation/planning: https://gist.github.com/cobraz/a0031905833bc58d233451fe537f3019

I'm pretty sure there are lots of people who wants that to help :)

@cobraz unfortunately the code for it is not in a public repo right now. I'll see what I can do to open-source it though.

@runeh I've checked out the PR, looks great - thank you so much for implementing that! I left a small comment regarding an edge case in default behavior, but otherwise - can't wait to try it out.

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 2.0.0-alpha.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants