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

undefined: avrotypegen #130

Open
gubtos opened this issue Jan 8, 2024 · 3 comments
Open

undefined: avrotypegen #130

gubtos opened this issue Jan 8, 2024 · 3 comments

Comments

@gubtos
Copy link

gubtos commented Jan 8, 2024

Given the following avro

{
    "type": "record",
    "name": "ItemEvent",
    "namespace": "search.item",
    "fields": [
        {
            "name": "id",
            "type": {
                "type": "string",
                "logicalType": "UUID"
            }
        },
        {
            "name": "modes",
            "type": {
                "type": "array",
                "items": {
                    "type": "enum",
                    "name": "mode",
                    "symbols": [
                        "SINGULAR"
                    ]
                }
            }
        }
    ]
}

And run a command like

avrogo -p is item-search.avsc 

The generated code dont imports the avrotypegen module, but uses it in the code. Given the following error:

undefined: avrotypegen compiler[UndeclaredName](https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName)
@gubtos
Copy link
Author

gubtos commented Jan 8, 2024

code generated

// Code generated by avrogen. DO NOT EDIT.

package is

import (
	"fmt"
	"strconv"
)

type ItemEvent struct {
	Id    string `json:"id"`
	Modes []Mode `json:"modes"`
}

// AvroRecord implements the avro.AvroRecord interface.
func (ItemEvent) AvroRecord() avrotypegen.RecordInfo {
	return avrotypegen.RecordInfo{
		Schema: `{"fields":[{"name":"id","type":{"logicalType":"UUID","type":"string"}},{"name":"modes","type":{"items":{"name":"mode","symbols":["SINGULAR"],"type":"enum"},"type":"array"}}],"name":"search.item.ItemEvent","type":"record"}`,
		Required: []bool{
			0: true,
			1: true,
		},
	}
}

type Mode int

const (
	ModeSINGULAR Mode = iota
)

var _Mode_strings = []string{
	"SINGULAR",
}

// String returns the textual representation of Mode.
func (e Mode) String() string {
	if e < 0 || int(e) >= len(_Mode_strings) {
		return "Mode(" + strconv.FormatInt(int64(e), 10) + ")"
	}
	return _Mode_strings[e]
}

// MarshalText implements encoding.TextMarshaler
// by returning the textual representation of Mode.
func (e Mode) MarshalText() ([]byte, error) {
	if e < 0 || int(e) >= len(_Mode_strings) {
		return nil, fmt.Errorf("Mode value %d is out of bounds", e)
	}
	return []byte(_Mode_strings[e]), nil
}

// UnmarshalText implements encoding.TextUnmarshaler
// by expecting the textual representation of Mode.
func (e *Mode) UnmarshalText(data []byte) error {
	// Note for future: this could be more efficient.
	for i, s := range _Mode_strings {
		if string(data) == s {
			*e = Mode(i)
			return nil
		}
	}
	return fmt.Errorf("unknown value %q for Mode", data)
}

@gubtos gubtos changed the title undefined: avrotypegencompiler undefined: avrotypegen Jan 8, 2024
@caio-northfleet-neon
Copy link

Hi @gubtos, I had the same issue and found that using -tokenize solves it.
Try calling avrogo -p is -tokenize item-search.avsc

@thiagodpf
Copy link

thiagodpf commented Aug 30, 2024

Hey @gubtos the same problem is happening to me!

I debugged locally here and noticed that the shouldImportAvroTypeGen() function is not behaving as it should.
I think the problem is in the use of the sort.Search() function. I believe this function does not fit the desired purpose...

Does it make sense to propose this fix?
What do you think?

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

3 participants