def test_json_validity():
    """Check that the jinja template generates the same json."""
    es_mapping = {
        '_all': {'enable': True},
        'numeric_detection': True,
        'date_detection': True,
        'properties': {
            'attr1': {'type': 'string'},
            'attr2': {'type': 'boolean'},
        },
    }
    jinja_template = mapping_to_jinja(es_mapping, 'mytype')
    es_gen_mapping_str = jinja2.Template(jinja_template).render()
    es_gen_mapping = json.loads(es_gen_mapping_str)
    assert es_mapping == es_gen_mapping
def test_json_validity():
    """Check that the jinja template generates the same json."""
    es_mapping = {
        '_all': {
            'enable': True
        },
        'numeric_detection': True,
        'date_detection': True,
        'properties': {
            'attr1': {
                'type': 'string'
            },
            'attr2': {
                'type': 'boolean'
            },
        },
    }
    jinja_template = mapping_to_jinja(es_mapping, 'mytype')
    es_gen_mapping_str = jinja2.Template(jinja_template).render()
    es_gen_mapping = json.loads(es_gen_mapping_str)
    assert es_mapping == es_gen_mapping
Exemple #3
0
    # read the schema
    schema = json.load(schema_file)

with open('config.json') as config_file:
    # load the configuration file
    config.load(json.load(config_file))

# generate the intermediate mapping
mapping = schema_to_mapping(schema, schema['id'], {}, config)

print('>> Intermediate mapping')
print(json.dumps(mapping, indent=4))
print('=' * 50)

# generate the jinja template
generated_template = mapping_to_jinja(mapping, 'person')

generated_template_dir = 'generated'
if not os.path.exists(generated_template_dir):
    os.mkdir(generated_template_dir)

generated_template_path = os.path.join(generated_template_dir,
                                       'generated_schema.json')

# write the template to a file so that it can be used by jinja
with open(generated_template_path, 'w') as gen_schema_file:
    gen_schema_file.write(generated_template)

# generate the final mapping from a import template overriding blocks
# of the generated one
with open('template.json') as overriding_template_file:
Exemple #4
0
    # read the schema
    schema = json.load(schema_file)

with open("config.json") as config_file:
    # load the configuration file
    config.load(json.load(config_file))

# generate the intermediate mapping
mapping = schema_to_mapping(schema, schema["id"], {}, config)

print(">> Intermediate mapping")
print(json.dumps(mapping, indent=4))
print("=" * 50)

# generate the jinja template
generated_template = mapping_to_jinja(mapping, "person")

generated_template_dir = "generated"
if not os.path.exists(generated_template_dir):
    os.mkdir(generated_template_dir)

generated_template_path = os.path.join(generated_template_dir, "generated_schema.json")

# write the template to a file so that it can be used by jinja
with open(generated_template_path, "w") as gen_schema_file:
    gen_schema_file.write(generated_template)

# generate the final mapping from a import template overriding blocks
# of the generated one
with open("template.json") as overriding_template_file:
    overriding_template = overriding_template_file.read()