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

Issue when schema key having . (dot) in it #71

Open
Abn02 opened this issue May 7, 2020 · 3 comments
Open

Issue when schema key having . (dot) in it #71

Abn02 opened this issue May 7, 2020 · 3 comments

Comments

@Abn02
Copy link

Abn02 commented May 7, 2020

when schema contains a key with dot in it
a field in UnmarshalJSON function creating with dot (.) in it and getting code errors

like template.hardwareIdReceived := false in below snippet

func (strct *Attrs) UnmarshalJSON(b []byte) error {
    template.hardwareIdReceived := false
    var jsonMap map[string]json.RawMessage
    if err := json.Unmarshal(b, &jsonMap); err != nil {
        return err
    }
    // parse all the defined properties
    for k, v := range jsonMap {
        switch k {
        case "template.hardwareId":
            if err := json.Unmarshal([]byte(v), &strct.TemplateHardwareId); err != nil {
                return err
             }
            template.hardwareIdReceived = true
        }
    }
    // check if template.hardwareId (a required property) was received
    if !template.hardwareIdReceived {
        return errors.New("\"template.hardwareId\" is required but was not present")
    }
    return nil
}

is there any way to avoid it ?

@tomsmalley
Copy link

The same is true for other symbols too, I ran into this for :.

@a-h
Copy link
Owner

a-h commented Dec 3, 2020

Sorry, I don't really understand how to reproduce this issue.

I had a try here, but it seems to work?

https://play.golang.org/p/47f5cXO52NJ

@bkmeneguello
Copy link

@a-h the problem happens on code generation. The variable generated for required attributes uses the json attribute name directly instead of converting to a safe go name using getGolangName

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

4 participants