mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +00:00
Merge pull request #23 from PaytmLabs/hotfix/scripts/multi-version-schema
scripts: Fix creation of schema from multi-version CRD
This commit is contained in:
commit
e9206c347e
1 changed files with 17 additions and 14 deletions
|
|
@ -88,6 +88,21 @@ def append_no_duplicates(obj, key, value):
|
|||
obj[key].append(value)
|
||||
|
||||
|
||||
def write_schema_file(schema, filename):
|
||||
schemaJSON = ""
|
||||
|
||||
schema = additional_properties(schema)
|
||||
schema = replace_int_or_string(schema)
|
||||
schemaJSON = json.dumps(schema)
|
||||
|
||||
# Dealing with user input here..
|
||||
filename = os.path.basename(filename)
|
||||
f = open(filename, "w")
|
||||
f.write(schemaJSON)
|
||||
f.close()
|
||||
print("JSON schema written to {filename}".format(filename=filename))
|
||||
|
||||
|
||||
if len(sys.argv) == 0:
|
||||
print("missing file")
|
||||
exit(1)
|
||||
|
|
@ -106,7 +121,6 @@ for crdFile in sys.argv[1:]:
|
|||
|
||||
filename_format = os.getenv("FILENAME_FORMAT", "{kind}_{version}")
|
||||
filename = ""
|
||||
schemaJSON = ""
|
||||
if "spec" in y and "validation" in y["spec"] and "openAPIV3Schema" in y["spec"]["validation"]:
|
||||
filename = filename_format.format(
|
||||
kind=y["spec"]["names"]["kind"],
|
||||
|
|
@ -115,9 +129,7 @@ for crdFile in sys.argv[1:]:
|
|||
).lower() + ".json"
|
||||
|
||||
schema = y["spec"]["validation"]["openAPIV3Schema"]
|
||||
schema = additional_properties(schema)
|
||||
schema = replace_int_or_string(schema)
|
||||
schemaJSON = json.dumps(schema)
|
||||
write_schema_file(schema, filename)
|
||||
elif "spec" in y and "versions" in y["spec"]:
|
||||
for version in y["spec"]["versions"]:
|
||||
if "schema" in version and "openAPIV3Schema" in version["schema"]:
|
||||
|
|
@ -128,15 +140,6 @@ for crdFile in sys.argv[1:]:
|
|||
).lower() + ".json"
|
||||
|
||||
schema = version["schema"]["openAPIV3Schema"]
|
||||
schema = additional_properties(schema)
|
||||
schema = replace_int_or_string(schema)
|
||||
schemaJSON = json.dumps(schema)
|
||||
|
||||
# Dealing with user input here..
|
||||
filename = os.path.basename(filename)
|
||||
f = open(filename, "w")
|
||||
f.write(schemaJSON)
|
||||
f.close()
|
||||
print("JSON schema written to {filename}".format(filename=filename))
|
||||
write_schema_file(schema, filename)
|
||||
|
||||
exit(0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue