oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Add method of calling arbitrary user templates

Open deefdragon opened this issue 1 year ago • 3 comments

Adds an option to the generate options in the configuration yaml, allowing for defining what additional user-defined templates to call. Data passed to template is an object containing both the array of operations as passed to most other templates, and the raw openapi specification.

Resolves https://github.com/deepmap/oapi-codegen/issues/1521

This is a draft for feedback reasons (should I include anything else to pass to the template, format the config options differently etc.), as well as I still need to test locally to confirm one or two things, and don't want it merged in until Ive tested that.

deefdragon avatar Apr 18 '24 08:04 deefdragon

Finally got around to doing the testing I wanted to do. Will get the merge conflicts resolved and mark as ready for review.

deefdragon avatar Apr 27 '24 19:04 deefdragon

Added an example set that goes into a bit of detail on how to use the user-provided templates.

The one thing that I was reminded of as I was working on this is that the types array is generates in a different location, and not passed in anywhere in the ops array. Types is one of the things that is likely to be most useful in user template generation stuff, but I don't want to make this PR any larger.

Adding the types to the provided struct would require code changes in other areas to pipe the type array up, and adding more data to the passed in object like that can be done over time.

deefdragon avatar May 06 '24 05:05 deefdragon

@jamietanna Is the awaiting reply tag supposed to auto-remove? And or was there anything else you would like me to change about this?

deefdragon avatar Jun 05 '24 03:06 deefdragon

I have a use case for this PR right now. I need to have the same code in every method of the StrictServerInterface implementation. I want to generate a struct, that wraps server implementation and adds tracing and validation code to each method

andrii-hrushetskyi avatar Aug 22 '24 13:08 andrii-hrushetskyi

I'll take a look tonight to update the Readme and see if there is anything else I need to do for the docs.

deefdragon avatar Aug 22 '24 16:08 deefdragon