Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json ld specification #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions json_ld/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import json_ld.langPack
60 changes: 60 additions & 0 deletions json_ld/langPack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
import chevron
import logging
logger = logging.getLogger(__name__)


# This makes sure we have somewhere to write the generated files
def setup(version_path):
if not os.path.exists(version_path):
os.makedirs(version_path)


def location(version):
return "cimpy." + version + ".Base"


base = {
"base_class": "Base",
"class_location": location
}

template_files = [{"filename": "json_ld_template.mustache", "ext": ".json"}]


def get_class_location(class_name, class_map, version):
pass


def _set_default(text, render):
return '0.0'


def set_enum_classes(new_enum_classes):
return


def set_float_classes(new_float_classes):
return


def run_template(version_path, class_details):
for template_info in template_files:
class_file = os.path.join(version_path, class_details['class_name']
+ template_info["ext"])
if not os.path.exists(class_file):
with open(class_file, 'w') as file:
template_path = os.path.join(os.getcwd(), 'json_ld/templates',
template_info["filename"])
class_details['setDefault'] = _set_default
with open(template_path) as f:
args = {
'data': class_details,
'template': f
}
output = chevron.render(**args)
file.write(output)


def resolve_headers(path):
pass
33 changes: 33 additions & 0 deletions json_ld/templates/json_ld_template.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "http://json-schema.org/schema#",
"$schemaVersion": "0.0.1",
"modelTags": "",
"title": "Smart Data Models - {{class_name}}",
"description": "{{class_comment}}",
"type": "object",
"allOf": [
{
"$ref": "https://smart-data-models.github.io/data-models/common-schema.json#/definitions/GSMA-Commons"
},
{
"$ref": "https://smart-data-models.github.io/data-models/common-schema.json#/definitions/Location-Commons"
},
{
"properties": {
"type": {
"type": "string",
"enum": [
"{{class_name}}"
],
"description": "Property. NGSI type. It has to be {{class_name}}"
},
{{#attributes}}
"{{label}}": {
"description": "Property. Model:'https://schema.org/Number'. {{comment}} Default: {{#setDefault}}{{dataType}}{{/setDefault}}",
"type": "number"
},
{{/attributes}}
}
}
]
}