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

Expose ids into template context #2098

Open
ZipFile opened this issue Oct 4, 2024 · 0 comments
Open

Expose ids into template context #2098

ZipFile opened this issue Oct 4, 2024 · 0 comments

Comments

@ZipFile
Copy link

ZipFile commented Oct 4, 2024

Is your feature request related to a problem? Please describe.

I want to implement basic schema registry out of generated models, so I need a way to include extra identifying info into my models.

Describe the solution you'd like

It would be nice for JSON Schema's $id and OpenAPI's operationId to be available within the template. Potentially something like x-id might be ok too, but if we're going this way, it is better to expose all of the x- fields.

Ideal solution would be an ability to do something like this in the template:

{%- if id_ %}
    _id: ClassVar[str] = "{{ id_ }}"
{%- endif %}

Describe alternatives you've considered

I've glanced the code, but it looks like there is no obvious way to extract ids. self.reference.path of DataModel instances looks unique enough, but that's not exactly an id defined in the schema. Given the nature of the schemas I work with, exposing it would be enough for now.

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

1 participant