def schema(ctx, output_file, version=None): """ Save the Mapfile schema to a file. Set the version parameter to output a specific version. Note output-file will be overwritten if it already exists. Examples: mappyfile schema C:/Temp/mapfile-schema.json Example of a specific version: mappyfile schema C:/Temp/mapfile-schema-7-6.json --version=7.6 """ validator = Validator() jsn = validator.get_versioned_schema(version) with codecs.open(output_file, "w", encoding="utf-8") as f: f.write(json.dumps(jsn, sort_keys=True, indent=4)) sys.exit(0)
def save_full_schema(output_file): validator = Validator() # check individual schema files fld = validator.get_schemas_folder() jsn_files = glob.glob(fld + '/*.json') for fn in jsn_files: check_schema(fn) # now check the combined schema jsn = validator.get_versioned_schema() full_schema = json.dumps(jsn, indent=4, sort_keys=False) with open(output_file, "w") as f: f.write(full_schema) check_schema(output_file)
def create(type, version=None): """ Create a new mappyfile object, using MapServer defaults (if any). Parameters ---------- s: type The mappyfile type to be stored in the __type__ property Returns ------- dict A Python dictionary representing the Mapfile object in the mappyfile format """ # get the schema for this type v = Validator() try: schema = v.get_versioned_schema(version=version, schema_name=type) except IOError: raise SyntaxError( "The mappyfile type '{}' does not exist!".format(type)) d = OrderedDict() d["__type__"] = type properties = sorted(schema["properties"].items()) for k, v in properties: if "default" in v: d[k] = v["default"] return d
def test_get_versioned_schema(): validator = Validator() jsn = validator.get_versioned_schema(7.6) # print(json.dumps(jsn, indent=4)) assert "defresolution" in jsn["properties"].keys()