Skip to content

Commit 6ae8c45

Browse files
authored
openapi2jsonschema.py now correctly fails if no FILE is passed (#244)
* openapi2jsonschema.py now correctly fails if no FILE is passed * Update acceptance tests
1 parent b7d7b4d commit 6ae8c45

File tree

4 files changed

+44
-49
lines changed

4 files changed

+44
-49
lines changed

acceptance.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resetCacheFolder() {
3636
}
3737

3838
@test "Pass when parsing a valid Kubernetes config JSON file" {
39-
run bin/kubeconform -kubernetes-version 1.17.1 -summary fixtures/valid.json
39+
run bin/kubeconform -kubernetes-version 1.20.0 -summary fixtures/valid.json
4040
[ "$status" -eq 0 ]
4141
[ "$output" = "Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0" ]
4242
}
@@ -134,17 +134,17 @@ resetCacheFolder() {
134134
}
135135

136136
@test "Fail when parsing a config with additional properties and strict set" {
137-
run bin/kubeconform -strict -kubernetes-version 1.16.0 fixtures/extra_property.yaml
137+
run bin/kubeconform -strict -kubernetes-version 1.20.0 fixtures/extra_property.yaml
138138
[ "$status" -eq 1 ]
139139
}
140140

141141
@test "Fail when parsing a config with duplicate properties and strict set" {
142-
run bin/kubeconform -strict -kubernetes-version 1.16.0 fixtures/duplicate_property.yaml
142+
run bin/kubeconform -strict -kubernetes-version 1.20.0 fixtures/duplicate_property.yaml
143143
[ "$status" -eq 1 ]
144144
}
145145

146146
@test "Pass when parsing a config with duplicate properties and strict NOT set" {
147-
run bin/kubeconform -kubernetes-version 1.16.0 fixtures/duplicate_property.yaml
147+
run bin/kubeconform -kubernetes-version 1.20.0 fixtures/duplicate_property.yaml
148148
[ "$status" -eq 0 ]
149149
}
150150

fixtures/valid.json

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,34 @@
11
{
2-
"apiVersion": "apps/v1beta1",
3-
"kind": "Deployment",
4-
"metadata": {
5-
"name": "nginx-deployment",
6-
"namespace": "default"
7-
},
8-
"spec": {
9-
"replicas": 2,
10-
"template": {
11-
"spec": {
12-
"affinity": { },
13-
"containers": [
14-
{
15-
"args": [ ],
16-
"command": [ ],
17-
"env": [ ],
18-
"envFrom": [ ],
19-
"image": "nginx:1.7.9",
20-
"lifecycle": { },
21-
"livenessProbe": { },
22-
"name": "nginx",
23-
"ports": [
24-
{
25-
"containerPort": 80,
26-
"name": "http"
27-
}
28-
],
29-
"readinessProbe": { },
30-
"resources": { },
31-
"securityContext": { },
32-
"volumeMounts": [ ]
33-
}
34-
],
35-
"hostMappings": [ ],
36-
"imagePullSecrets": [ ],
37-
"initContainers": [ ],
38-
"nodeSelector": { },
39-
"securityContext": { },
40-
"tolerations": [ ],
41-
"volumes": [ ]
42-
}
2+
"apiVersion": "v1",
3+
"kind": "ReplicationController",
4+
"metadata": {
5+
"name": "bob"
6+
},
7+
"spec": {
8+
"replicas": 2,
9+
"selector": {
10+
"app": "nginx"
11+
},
12+
"template": {
13+
"metadata": {
14+
"name": "nginx",
15+
"labels": {
16+
"app": "nginx"
17+
}
18+
},
19+
"spec": {
20+
"containers": [
21+
{
22+
"name": "nginx",
23+
"image": "nginx",
24+
"ports": [
25+
{
26+
"containerPort": 80
27+
}
28+
]
29+
}
30+
]
4331
}
44-
},
45-
"status": { }
32+
}
33+
}
4634
}

scripts/acceptance.bats

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,10 @@ setup() {
7272
run diff prometheus_v1.json ./fixtures/prometheus_v1-denyRootAdditionalProperties.json
7373
[ "$status" -eq 0 ]
7474
}
75+
76+
@test "Should output an error if no file is passed" {
77+
run ./openapi2jsonschema.py
78+
[ "$status" -eq 1 ]
79+
[ "${lines[0]}" == 'Missing FILE parameter.' ]
80+
[ "${lines[1]}" == 'Usage: ./openapi2jsonschema.py [FILE]' ]
81+
}

scripts/openapi2jsonschema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def construct_value(load, node):
122122

123123

124124
if __name__ == "__main__":
125-
if len(sys.argv) == 0:
126-
print("missing file")
125+
if len(sys.argv) < 2:
126+
print('Missing FILE parameter.\nUsage: %s [FILE]' % sys.argv[0])
127127
exit(1)
128128

129129
for crdFile in sys.argv[1:]:

0 commit comments

Comments
 (0)