-
Notifications
You must be signed in to change notification settings - Fork 15
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
Support a schema in plan for vars
#6
Comments
I think the simplest approach would be to use JSON schema specifications for the plans and parse the plan yaml files against it. The https://github.com/go-openapi/validate project support validating an input string against a schema. A simple example is shown in the Godoc documentation of https://godoc.org/github.com/go-openapi/validate#AgainstSchema. The documentation states that it can validate both json and yaml formats. // Example using encoding/json as unmarshaller
var schemaJSON = `
{
"properties": {
"name": {
"type": "string",
"pattern": "^[A-Za-z]+$",
"minLength": 1
}
},
"patternProperties": {
"address-[0-9]+": {
"type": "string",
"pattern": "^[\\s|a-z]+$"
}
},
"required": [
"name"
],
"additionalProperties": false
}`
schema := new(spec.Schema)
json.Unmarshal([]byte(schemaJSON), schema)
input := map[string]interface{}{}
// JSON data to validate
inputJSON := `{"name": "Ivan","address-1": "sesame street"}`
json.Unmarshal([]byte(inputJSON), &input)
// strfmt.Default is the registry of recognized formats
err := validate.AgainstSchema(schema, input, strfmt.Default)
if err != nil {
fmt.Printf("JSON does not validate against schema: %v", err)
} else {
fmt.Printf("OK")
} |
# This is the 1st commit message: Added config command to output Shuttle version, Environment Variables and Plan # This is the commit message lunarway#2: Removed unnecessary loop Signed-off-by: Michael Bui <[email protected]> # This is the commit message lunarway#3: Display plan + head for git plans Signed-off-by: Michael Bui <[email protected]> # This is the commit message lunarway#4: Added test cases, use RunE instead of Run, move Plan output above Environment output Signed-off-by: Michael Bui <[email protected]> # This is the commit message lunarway#5: Update test case name Signed-off-by: Michael Bui <[email protected]> # This is the commit message lunarway#6: Removed unnecessary loop
It is hard and error-prone to use the
vars
system. Whatvars
can be used? Did I misspell some of them?Add some level of schema for the
vars
, so required vars and optional vars are easily validatedThe text was updated successfully, but these errors were encountered: