Skip to content

Conversation

@ekazakas
Copy link
Contributor

@ekazakas ekazakas commented Apr 14, 2025

Goal of this PR

In case of struct generation from schema registry entries, we can pass not only numerical versions, but also a 'latest' version.

How did I test it?

Manual test with local schema registry.

/home/ekazakas/.cache/JetBrains/GoLand2024.3/tmp/GoLand/___go_build_github_com_hamba_avro_v2_cmd_avrogen -pkg test -schemaregistry http://localhost:8081 print_report:latest #gosetup
// Code generated by avro/gen. DO NOT EDIT.
package test

// PrintReport is a generated struct.
type PrintReport struct {
	ID   int    `avro:"id"`
	Ref  string `avro:"ref"`
	Flag int    `avro:"flag"`
}

Process finished with the exit code 0
/home/ekazakas/.cache/JetBrains/GoLand2024.3/tmp/GoLand/___go_build_github_com_hamba_avro_v2_cmd_avrogen -pkg test -schemaregistry http://localhost:8081 print_report:1 #gosetup
// Code generated by avro/gen. DO NOT EDIT.
package test

// PrintReport is a generated struct.
type PrintReport struct {
	ID   int    `avro:"id"`
	Ref  string `avro:"ref"`
	Flag int    `avro:"flag"`
}

Process finished with the exit code 0

@nrwiersma nrwiersma requested a review from Copilot April 15, 2025 05:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces the ability to fetch the latest schema from the schema registry by allowing the "latest" version to be passed as a parameter.

  • Refactored schema fetching logic via a new helper function (schemaFromRegistry).
  • Updated parseSubjectVersion to return the version as a string to accommodate the "latest" keyword.
Comments suppressed due to low confidence (1)

cmd/avrogen/main.go:227

  • [nitpick] The function name 'parseSubjectVersion' may be misleading now that it returns the version as a string instead of an integer. Consider renaming it (or adding a clarifying comment) to better reflect its behavior.
func parseSubjectVersion(entry string) (string, string, error) {

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.

The Copilot suggestion here is good. Otherwise it looks fine.

@ekazakas ekazakas requested a review from nrwiersma April 16, 2025 05:38
@nrwiersma nrwiersma requested a review from Copilot April 17, 2025 05:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds functionality to allow fetching the latest schema from the schema registry when the "latest" keyword is used as the version parameter.

  • Replaces inline client initialization and subject/version parsing with a new helper function, schemaFromRegistry.
  • Refactors parseSubjectVersion into splitParameterEntry and integrates handling for the "latest" version case.
Comments suppressed due to low confidence (1)

cmd/avrogen/main.go:227

  • [nitpick] Consider renaming 'splitParameterEntry' to 'parseSchemaRegistryEntry' to more clearly convey that it parses the subject and version from the registry entry.
func splitParameterEntry(entry string) (string, string, error) {

@nrwiersma nrwiersma merged commit 98fc9f5 into hamba:main Apr 17, 2025
13 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