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

Feature request: Generating multiple type definitions with prefix/suffix and modification #12

Open
okuramasafumi opened this issue Oct 11, 2024 · 3 comments

Comments

@okuramasafumi
Copy link
Contributor

Motivation

We want to generate two types, one is snake_case_key and another is camelCaseKey because our React app wants camelCaseKey for internal use, but also Rails API outputs snake_case_key.
Currently we transform types with TypeScript, but it is difficult to understand, so it's better to let Typelizer do that.

Details

Currently we can modify keys with something like config.properties_transformer = ->(properties) { properties.map{ _1.name = _1.name.to_s.camelize and _1 } } but this makes all keys camelCase. Basically we want to do generation twice.

We have Generator class and Writer class. Should we have multiple generators, or writers?

Additional info

It's more like a discussion rather than an issue. I'd love to implement this feature if we reach some conclusion.

@skryukov
Copy link
Owner

Hey @okuramasafumi, thanks for the feature request! Yes, I think multiple outputs make sense for generating input/output types with different configurations. null_strategy might be another option one might want to modify. I can't comment on implementation details right away, but I like the idea.

@okuramasafumi
Copy link
Contributor Author

I've come up with the following API:

Typelizer.add_writer do |config|
  # Here comes the same config as normal
end

Then we can use multiple instances of Writer class in https://github.com/skryukov/typelizer/blob/main/lib/typelizer/generator.rb#L11

@skryukov
Copy link
Owner

Looks great @okuramasafumi!

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