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

Support a schema in plan for vars #6

Open
emilingerslev opened this issue Oct 2, 2018 · 1 comment
Open

Support a schema in plan for vars #6

emilingerslev opened this issue Oct 2, 2018 · 1 comment
Labels
enhancement New feature or request

Comments

@emilingerslev
Copy link
Contributor

It is hard and error-prone to use the vars system. What vars 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 validated

@emilingerslev emilingerslev added the enhancement New feature or request label Oct 2, 2018
@Crevil
Copy link
Member

Crevil commented Dec 17, 2018

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")
}

michaelbui99 added a commit to michaelbui99/shuttle that referenced this issue Nov 18, 2022
# 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 <michaelbui99@hotmail.com>

# This is the commit message lunarway#3:

Display plan + head for git plans

Signed-off-by: Michael Bui <michaelbui99@hotmail.com>

# 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 <michaelbui99@hotmail.com>

# This is the commit message lunarway#5:

Update test case name

Signed-off-by: Michael Bui <michaelbui99@hotmail.com>

# This is the commit message lunarway#6:

Removed unnecessary loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants