-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
55 lines (49 loc) · 1.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/alecthomas/jsonschema"
"github.com/concourse/concourse/atc"
)
func stepSchema(schema *jsonschema.Schema) {
stepDef := schema.Definitions["Step"]
// thx: https://gist.github.com/4662752c4af75b3220d94b657683d090
// https://concourse-ci.org/steps.html#schema.step
stepConfigs := []atc.StepConfig{
&atc.GetStep{},
&atc.PutStep{},
&atc.TaskStep{},
&atc.SetPipelineStep{},
&atc.LoadVarStep{},
&atc.InParallelStep{},
&atc.DoStep{},
&atc.TryStep{},
}
for _, s := range stepConfigs {
stepSchema := jsonschema.Reflect(s)
stepDef.AnyOf = append(stepDef.AnyOf, stepSchema.Type)
for subName, subDef := range stepSchema.Definitions {
if _, present := schema.Definitions[subName]; !present {
schema.Definitions[subName] = subDef
}
}
}
stepDef.Required = nil
schema.Definitions["Step"].Properties = nil
schema.Definitions["Step"].Type = ""
schema.Definitions["Step"].AdditionalProperties = nil
}
func main() {
var pipelineConfig atc.Config
schema := jsonschema.Reflect(&pipelineConfig)
stepSchema(schema)
schema.AdditionalProperties = json.RawMessage("true")
schema.Definitions["CheckEvery"].Type = "string"
reflected, err := schema.MarshalJSON()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
fmt.Fprintln(os.Stdout, string(reflected))
}