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

Go time import is misplaced in some circumstances. #2530

Closed
rekram1-node opened this issue Mar 9, 2024 · 1 comment · Fixed by #2531
Closed

Go time import is misplaced in some circumstances. #2530

rekram1-node opened this issue Mar 9, 2024 · 1 comment · Fixed by #2531

Comments

@rekram1-node
Copy link
Contributor

My fix for #2528 fixed the bug where Go code was missing the time import. However, it seems a new bug was introduced where in some cases the time import is not appearing at the top of the generated file.

Reproduction steps:

{
    "type": "object",
    "properties": {
        "timeRange": {
            "type": "array",
            "items": {
                "type": "string",
                "format": "date-time"
            }
        }
    }
}

Generated Code:

// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse and unparse this JSON data, add this code to your project and do:
//
//    models, err := UnmarshalModels(bytes)
//    bytes, err = models.Marshal()

package generated

import "encoding/json"

func UnmarshalModels(data []byte) (Models, error) {
	var r Models
	err := json.Unmarshal(data, &r)
	return r, err
}

func (r *Models) Marshal() ([]byte, error) {
	return json.Marshal(r)
}

import "time"

type Models struct {
	TimeRange []time.Time `json:"timeRange,omitempty"`
}

Note the time import is not at the top of the file like the other import. This is a bug that causes the go code to not compile (syntax error).

Looking into a fix for this hopefully will have a Pull Request ready shortly.

@rekram1-node
Copy link
Contributor Author

Found the issue, basically just a 1 liner fix that I missed the first time around.

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

Successfully merging a pull request may close this issue.

1 participant