Skip to content

Commit 9fdb853

Browse files
committed
added anyof for some fields as the fields support anyof object or string
1 parent d140a69 commit 9fdb853

4 files changed

Lines changed: 144 additions & 40 deletions

File tree

docs/hack/config/schemas/main.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,56 @@ func genSchema(schema *jsonschema.Schema, schemaFile string) {
4141
if isOpenAPISpec {
4242
prefix = " "
4343
}
44+
45+
// vars
46+
vars, ok := schema.Properties.Get("vars")
47+
if ok {
48+
vars.(*jsonschema.Schema).OneOf = modifyOneOf(vars)
49+
vars.(*jsonschema.Schema).PatternProperties = nil
50+
}
51+
52+
// pipelines
53+
pipelines, ok := schema.Properties.Get("pipelines")
54+
if ok {
55+
pipelines.(*jsonschema.Schema).OneOf = modifyOneOf(pipelines)
56+
pipelines.(*jsonschema.Schema).PatternProperties = nil
57+
}
58+
59+
// commands
60+
commands, ok := schema.Properties.Get("commands")
61+
if ok {
62+
commands.(*jsonschema.Schema).OneOf = modifyOneOf(commands)
63+
commands.(*jsonschema.Schema).PatternProperties = nil
64+
}
65+
66+
// images
67+
images, ok := schema.Properties.Get("images")
68+
if ok {
69+
images.(*jsonschema.Schema).OneOf = modifyOneOf(images)
70+
images.(*jsonschema.Schema).PatternProperties = nil
71+
}
72+
73+
//deployments
74+
deployments, ok := schema.Properties.Get("deployments")
75+
if ok {
76+
deployments.(*jsonschema.Schema).OneOf = modifyOneOf(deployments)
77+
deployments.(*jsonschema.Schema).PatternProperties = nil
78+
}
79+
80+
//dependencies
81+
dependencies, ok := schema.Properties.Get("dependencies")
82+
if ok {
83+
dependencies.(*jsonschema.Schema).OneOf = modifyOneOf(dependencies)
84+
dependencies.(*jsonschema.Schema).PatternProperties = nil
85+
}
86+
87+
//pullSecrets
88+
pullSecrets, ok := schema.Properties.Get("pullSecrets")
89+
if ok {
90+
pullSecrets.(*jsonschema.Schema).OneOf = modifyOneOf(pullSecrets)
91+
pullSecrets.(*jsonschema.Schema).PatternProperties = nil
92+
}
93+
4494
schemaJSON, err := json.MarshalIndent(schema, prefix, " ")
4595
if err != nil {
4696
panic(err)
@@ -75,3 +125,18 @@ func genSchema(schema *jsonschema.Schema, schemaFile string) {
75125
panic(err)
76126
}
77127
}
128+
129+
func modifyOneOf(field interface{}) []*jsonschema.Schema {
130+
return []*jsonschema.Schema{
131+
{
132+
Type: "object",
133+
AdditionalProperties: &jsonschema.Schema{
134+
Type: "string",
135+
},
136+
},
137+
{
138+
Type: "object",
139+
PatternProperties: field.(*jsonschema.Schema).PatternProperties,
140+
},
141+
}
142+
}

docs/schemas/config-jsonschema.json

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,6 @@
339339
}
340340
},
341341
"type": "object",
342-
"required": [
343-
"name"
344-
],
345342
"description": "DependencyConfig defines the devspace dependency"
346343
},
347344
"DeploymentConfig": {
@@ -1954,9 +1951,6 @@
19541951
}
19551952
},
19561953
"type": "object",
1957-
"required": [
1958-
"name"
1959-
],
19601954
"description": "Variable describes the var definition"
19611955
},
19621956
"VariableCommand": {
@@ -2006,11 +2000,22 @@
20062000
"description": "Functions are POSIX functions that can be used within pipelines. Those functions can also be imported by\nimports."
20072001
},
20082002
"pipelines": {
2009-
"patternProperties": {
2010-
".*": {
2011-
"$ref": "#/$defs/Pipeline"
2003+
"oneOf": [
2004+
{
2005+
"additionalProperties": {
2006+
"type": "string"
2007+
},
2008+
"type": "object"
2009+
},
2010+
{
2011+
"patternProperties": {
2012+
".*": {
2013+
"$ref": "#/$defs/Pipeline"
2014+
}
2015+
},
2016+
"type": "object"
20122017
}
2013-
},
2018+
],
20142019
"type": "object",
20152020
"description": "Pipelines are the work blocks that DevSpace should execute when devspace dev, devspace build, devspace deploy or devspace purge\nis called. Pipelines are defined through a special POSIX script that allows you to use special commands\nsuch as create_deployments, start_dev, build_images etc. to signal DevSpace you want to execute\na specific functionality. The pipelines dev, build, deploy and purge are special and will override\nthe default functionality of the respective command if defined. All other pipelines can be either run\nvia the devspace run-pipeline command or used within another pipeline through run_pipelines."
20162021
},
@@ -2042,20 +2047,42 @@
20422047
"description": "Dev holds development configuration. Each dev configuration targets a single pod and enables certain dev services on that pod\nor even rewrites it if certain changes are requested, such as adding an environment variable or changing the entrypoint.\nDev allows you to:\n- sync local folders to the Kubernetes pod\n- port forward remote ports to your local computer\n- forward local ports into the Kubernetes pod\n- configure an ssh tunnel to the Kubernetes pod\n- proxy local commands to the container\n- restart the container on file changes"
20432048
},
20442049
"vars": {
2045-
"patternProperties": {
2046-
".*": {
2047-
"$ref": "#/$defs/Variable"
2050+
"oneOf": [
2051+
{
2052+
"additionalProperties": {
2053+
"type": "string"
2054+
},
2055+
"type": "object"
2056+
},
2057+
{
2058+
"patternProperties": {
2059+
".*": {
2060+
"$ref": "#/$defs/Variable"
2061+
}
2062+
},
2063+
"type": "object"
20482064
}
2049-
},
2065+
],
20502066
"type": "object",
20512067
"description": "Vars are config variables that can be used inside other config sections to replace certain values dynamically"
20522068
},
20532069
"commands": {
2054-
"patternProperties": {
2055-
".*": {
2056-
"$ref": "#/$defs/CommandConfig"
2070+
"oneOf": [
2071+
{
2072+
"additionalProperties": {
2073+
"type": "string"
2074+
},
2075+
"type": "object"
2076+
},
2077+
{
2078+
"patternProperties": {
2079+
".*": {
2080+
"$ref": "#/$defs/CommandConfig"
2081+
}
2082+
},
2083+
"type": "object"
20572084
}
2058-
},
2085+
],
20592086
"type": "object",
20602087
"description": "Commands are custom commands that can be executed via 'devspace run COMMAND'. These commands are run within a pseudo bash\nthat also allows executing special commands such as run_watch or is_equal."
20612088
},

docs/schemas/config-openapi.json

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,6 @@
347347
}
348348
},
349349
"type": "object",
350-
"required": [
351-
"name"
352-
],
353350
"description": "DependencyConfig defines the devspace dependency"
354351
},
355352
"DeploymentConfig": {
@@ -1962,9 +1959,6 @@
19621959
}
19631960
},
19641961
"type": "object",
1965-
"required": [
1966-
"name"
1967-
],
19681962
"description": "Variable describes the var definition"
19691963
},
19701964
"VariableCommand": {
@@ -2014,11 +2008,17 @@
20142008
"description": "Functions are POSIX functions that can be used within pipelines. Those functions can also be imported by\nimports."
20152009
},
20162010
"pipelines": {
2017-
"patternProperties": {
2018-
".*": {
2019-
"$ref": "#/definitions/Config/$defs/Pipeline"
2011+
"oneOf": [
2012+
{
2013+
"additionalProperties": {
2014+
"type": "string"
2015+
},
2016+
"type": "object"
2017+
},
2018+
{
2019+
"type": "object"
20202020
}
2021-
},
2021+
],
20222022
"type": "object",
20232023
"description": "Pipelines are the work blocks that DevSpace should execute when devspace dev, devspace build, devspace deploy or devspace purge\nis called. Pipelines are defined through a special POSIX script that allows you to use special commands\nsuch as create_deployments, start_dev, build_images etc. to signal DevSpace you want to execute\na specific functionality. The pipelines dev, build, deploy and purge are special and will override\nthe default functionality of the respective command if defined. All other pipelines can be either run\nvia the devspace run-pipeline command or used within another pipeline through run_pipelines."
20242024
},
@@ -2050,20 +2050,32 @@
20502050
"description": "Dev holds development configuration. Each dev configuration targets a single pod and enables certain dev services on that pod\nor even rewrites it if certain changes are requested, such as adding an environment variable or changing the entrypoint.\nDev allows you to:\n- sync local folders to the Kubernetes pod\n- port forward remote ports to your local computer\n- forward local ports into the Kubernetes pod\n- configure an ssh tunnel to the Kubernetes pod\n- proxy local commands to the container\n- restart the container on file changes"
20512051
},
20522052
"vars": {
2053-
"patternProperties": {
2054-
".*": {
2055-
"$ref": "#/definitions/Config/$defs/Variable"
2053+
"oneOf": [
2054+
{
2055+
"additionalProperties": {
2056+
"type": "string"
2057+
},
2058+
"type": "object"
2059+
},
2060+
{
2061+
"type": "object"
20562062
}
2057-
},
2063+
],
20582064
"type": "object",
20592065
"description": "Vars are config variables that can be used inside other config sections to replace certain values dynamically"
20602066
},
20612067
"commands": {
2062-
"patternProperties": {
2063-
".*": {
2064-
"$ref": "#/definitions/Config/$defs/CommandConfig"
2068+
"oneOf": [
2069+
{
2070+
"additionalProperties": {
2071+
"type": "string"
2072+
},
2073+
"type": "object"
2074+
},
2075+
{
2076+
"type": "object"
20652077
}
2066-
},
2078+
],
20672079
"type": "object",
20682080
"description": "Commands are custom commands that can be executed via 'devspace run COMMAND'. These commands are run within a pseudo bash\nthat also allows executing special commands such as run_watch or is_equal."
20692081
},

pkg/devspace/config/versions/latest/schema.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ type Terminal struct {
12341234
// DependencyConfig defines the devspace dependency
12351235
type DependencyConfig struct {
12361236
// Name is used internally
1237-
Name string `yaml:"name" json:"name"`
1237+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
12381238

12391239
// Source holds the dependency project
12401240
Source *SourceConfig `yaml:",inline" json:",inline"`
@@ -1460,7 +1460,7 @@ func (c *CommandConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
14601460
// Variable describes the var definition
14611461
type Variable struct {
14621462
// Name is the name of the variable
1463-
Name string `yaml:"name" json:"name"`
1463+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
14641464

14651465
// Value is a shortcut for using source: none and default: my-value
14661466
Value interface{} `yaml:"value,omitempty" json:"value,omitempty" jsonschema:"oneof_type=string;integer;boolean" jsonschema_extras:"group=static,group_name=Static Value"`
@@ -1497,8 +1497,8 @@ type Variable struct {
14971497
// system.
14981498
Commands []VariableCommand `yaml:"commands,omitempty" json:"commands,omitempty" jsonschema_extras:"group=execution"`
14991499

1500-
// AlwaysResolve makes sure this variable will always be resolved and not only if it is used somewhere
1501-
AlwaysResolve bool `yaml:"alwaysResolve,omitempty" json:"alwaysResolve,omitempty"`
1500+
// AlwaysResolve makes sure this variable will always be resolved and not only if it is used somewhere. Defaults to true.
1501+
AlwaysResolve *bool `yaml:"alwaysResolve,omitempty" json:"alwaysResolve,omitempty"`
15021502

15031503
// Source defines where the variable should be taken from
15041504
Source VariableSource `yaml:"source,omitempty" json:"source,omitempty" jsonschema:"enum=all,enum=env,enum=input,enum=command,enum=none"`

0 commit comments

Comments
 (0)