Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"inputs": [
{
"id": "requestJson",
"type": "promptString",
"description": "Enter the JSON request string for the CLI",
"default": "{\"req\":\"card.attn\",\"mode\":\"watchdog\",\"seconds\":30}"
}
],
"configurations": [
{
"name": "Launch Notecard CLI",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/notecard",
"args": ["-req", "${input:requestJson}"],
"env": {
"BLUES": "abucknall@blues.com"
}
},
{
"name": "Launch Notehub CLI",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/notehub",
"args": ["-req", "${input:requestJson}"]
}
]
}
25 changes: 19 additions & 6 deletions notecard/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func fetchAndCacheSchema(url string, verbose bool) (io.Reader, error) {
}

func formatErrorMessage(reqType string, errUnformatted error) (err error) {
// Check if the error is nil
if errUnformatted == nil {
return nil
}

// Convert the error to a string
errMsg := errUnformatted.Error()

// Define constants
Expand Down Expand Up @@ -230,15 +236,22 @@ func resolveSchemaError(reqMap map[string]interface{}, verbose bool) (err error)
} else if reqTypeStr == "" {
err = fmt.Errorf("no request type specified")
} else {
var reqSchema *jsonschema.Schema
reqSchema, err = jsonschema.Compile(filepath.Join(cacheDir, reqTypeStr+".req.notecard.api.json"))
if err == nil {
err = reqSchema.Validate(reqMap)
if !verbose {
err = formatErrorMessage(reqTypeStr, err)
// Validate against the specific request schema
schemaPath := filepath.Join(cacheDir, reqTypeStr+".req.notecard.api.json")
if _, err = os.Stat(schemaPath); os.IsNotExist(err) {
err = fmt.Errorf("unknown request type: %s", reqTypeStr)
} else if err == nil {
var reqSchema *jsonschema.Schema
reqSchema, err = jsonschema.Compile(schemaPath)
if err == nil {
err = reqSchema.Validate(reqMap)
if err != nil && !verbose {
err = formatErrorMessage(reqTypeStr, err)
}
}
}
}

return err
}

Expand Down