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

Generate code from custom templates #1521

Open
sagikazarmark opened this issue Mar 28, 2024 · 4 comments · May be fixed by #1544
Open

Generate code from custom templates #1521

sagikazarmark opened this issue Mar 28, 2024 · 4 comments · May be fixed by #1544

Comments

@sagikazarmark
Copy link

I'd like to integrate models and types with a custom (in-house built) framework.

In order to do that, I'd like to generate custom marshaler/unmarshaler functions.

It would be nice if I could add arbitrary templates to the code generation process.

One thing I tried is overriding templates for a server that I don't use. To complicate things, we still use the Chi integration, so I actually need to support two servers at the same time...which is not allowed at the moment.

As a result, I'm now overriding Chi templates by copying the original ones and extending them with my custom code which is not ideal IMO.

@jamietanna
Copy link
Collaborator

Hey, I'm just in the middle of a complete re-write of our docs to improve this - if you see https://github.com/deepmap/oapi-codegen?tab=readme-ov-file#making-changes-to-code-generation and scroll to the code at the bottom ,it should be possible to specify your own (local/remote) templates for generation - does that work for you or have I misunderstood?

@sagikazarmark
Copy link
Author

What I’d like to do is basically add custom templates that contain additional code (for example: mapping to internal types).

My understanding is that the current template config only allows me to override templates already defined. Is that correct?

@deefdragon
Copy link
Contributor

It will pull in any templates provided in the user-templates object. Unfortunately, I did not set it up to have a way to call those templates.

As such, you need to call those templates somewhere that already exists, which will require over-riding at-least one existing template.

@deefdragon
Copy link
Contributor

Made the PR ready for review. Could use a check on if the documentation I put in the readme makes sense @sagikazarmark

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