tera icon indicating copy to clipboard operation
tera copied to clipboard

Hook template variables resolution

Open truchi opened this issue 2 years ago • 3 comments

Hello,

I'm prototyping an OpenAPI generator with Tera (great job btw).

I am facing this issue: in OpenAPI, objects can reference other objects. To deal with this I have the option:

  • To provide a deref function to the template engine, and just give the openapi.yaml entry as the context. Simple, but has the drawback that the template is not agnostic from the input (deref calls in the templates must be updated after using/unusing $ref in the yaml),
  • To resolve the full OpenAPI data before rendering the templates. Harder, and infinite recursion issues.

It would be ideal to have the chance to "hook" variable resolution (is that how you call it?) so dereferencing could happen automagically in the templates.

Is that something that I can do with Tera currently? Or how could I emulate it? Do you have broader ideas on how to tackle this issue?

Thank you!

truchi avatar Sep 23 '23 11:09 truchi

We don't have this concept of pointers in the data in either Tera v1 or v2. No plans to add any hook in there either

Keats avatar Sep 23 '23 19:09 Keats

Noted. Thanks.

truchi avatar Sep 23 '23 20:09 truchi

Note: it's not even possible to implement deref since pub fn register_function<F: Fn(...) -> ... + 'static>.

truchi avatar Sep 23 '23 21:09 truchi