Skip to content

Conversation

@ljank
Copy link
Contributor

@ljank ljank commented Apr 22, 2025

Goal of this PR

We're looking for ways to pass down some schema metadata to the template, e.g. we have a need for the original schema subject identifier in the generated Go struct.

This change allows to pass arbitrary metadata while parsing the schema and have that metadata available in the template.

How did I test it?

go test

@ljank ljank force-pushed the feature/gen/add-metadata branch 3 times, most recently from e7ca557 to 63b6234 Compare April 23, 2025 07:04
@nrwiersma
Copy link
Member

@ljank
Copy link
Contributor Author

ljank commented Apr 24, 2025

Unfortunately current metadata is not enough (at least very inconvenient) when it comes to mapping of schema metadata -> typedef metadata. In the template Typedefs have different names compared to schemas:

avro/gen/gen.go

Lines 311 to 316 in 5c80dfb

func (g *Generator) resolveTypeName(s avro.NamedSchema) string {
if g.fullName {
return g.nameCaser.ToPascal(s.FullName())
}
return g.nameCaser.ToPascal(s.Name())
}

Since Typedef names are rendered using unexported nameCaser and unexported resolveTypeName(), we don't know the final Typedef name in advance and therefore can't set corresponding metadata key for access from the template.

Exporting nameCaser and/or resolveTypeName() doesn't feel right, therefore we suggest adding metadata along with the schema when calling (Generator) Parse() :)

@ljank
Copy link
Contributor Author

ljank commented Apr 29, 2025

@nrwiersma what do you think? can we proceed with the proposed change? 🙏🏻

@nrwiersma
Copy link
Member

@ljank I am away at the moment, will take a look when I find some time.

Copy link
Member

@nrwiersma nrwiersma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the linter issues, then I think it is good to go.

We're looking for ways to pass down some schema metadata to the template, e.g. we have a need for the original schema subject identifier in the generated Go struct.

This change allows to pass arbitrary metadata while parsing the schema and have that metadata available in the template.
@ljank ljank force-pushed the feature/gen/add-metadata branch from d32371d to 77e7dab Compare May 9, 2025 15:51
@nrwiersma nrwiersma merged commit 13d0f22 into hamba:main May 9, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants