-
Notifications
You must be signed in to change notification settings - Fork 30
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
add support for root-node #10
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ var ( | |
outputFile = kingpin.Flag("out-file", "filename for output; default is <schema>_schematype.go").Short('o').String() | ||
packageName = kingpin.Flag("package", `package name for generated file; default is "main"`).Default("main").String() | ||
rootTypeName = kingpin.Flag("root-type", `name of root type; default is generated from the filename`).String() | ||
rootNodeName = kingpin.Flag("root-node", `name of root node of json; default is whole file`).String() | ||
typeNamesPrefix = kingpin.Flag("prefix", `prefix for non-root types`).String() | ||
inputFile = kingpin.Arg("input", "file containing a valid JSON schema").Required().ExistingFile() | ||
) | ||
|
@@ -690,8 +691,22 @@ func main() { | |
} | ||
|
||
var s metaSchema | ||
if err = json.Unmarshal(file, &s); err != nil { | ||
log.Fatalln("Error parsing JSON:", err) | ||
if *rootNodeName != "" { | ||
|
||
var sub map[string]metaSchema | ||
if err = json.Unmarshal(file, &sub); err != nil { | ||
log.Fatalln("Error parsing JSON:", err) | ||
} | ||
node, ok := sub[*rootNodeName] | ||
if ok == false { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
log.Fatalln(fmt.Sprintf("Error JSON node '%s' does not exists:", *rootNodeName), err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of combining |
||
} | ||
//log.Panicf("Error reading file %v:", node) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented-out code. |
||
s = node | ||
} else { | ||
if err = json.Unmarshal(file, &s); err != nil { | ||
log.Fatalln("Error parsing JSON:", err) | ||
} | ||
} | ||
|
||
schemaName := strings.Split(filepath.Base(*inputFile), ".")[0] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this empty line.