Git Product home page Git Product logo

schemapi's People

Contributors

empireerwinkooi avatar jakevdp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

schemapi's Issues

pip install on PyCharm for version 0.3.0 did not generate SchemaModuleGenerator Class

Only have JSONSchema and JSONSchemaPlugin available. Therefore, after putting "import schemapi" and then api = schemapi.SchemaModuleGenerator(schemaFilename, root_name='MachineData'), when executing it gives me the error module 'schemapi' has no attribute 'SchemaModuleGenerator'.

Never had an issue like this from python libraries I have added in the past and could use some guidance on how to resolve this. Was looking forward to investigating using this api to help generate json payloads from data that I have acquired and mapped to python dictionaries using a schema.

Please advise.

Thanks,

Bob Sloma

Non-conforming property/trait names

There's one issue here that I'm not sure how to address: as this package is currently set up, all JSONschema property names must be valid Python variable names. Currently schemapi contains a hack that removes offending characters when constructing the classes: https://github.com/altair-viz/schemapi/blob/master/schemapi/utils/core.py#L38

This is clearly not ideal, as the resulting dictionaries will not match the schema.

One way to make this work would be to create the traitlets classes in a non-standard way in order to handle arbitrary trait names: e.g.

Foo = T.MetaHasTraits('Foo', (T.HasTraits,), {'$schema': T.Unicode()})
print(Foo.class_traits())
{'$schema': <traitlets.traitlets.Unicode at 0x1069dd668>}

I don't think this is ideal.

Another way forward would be to not allow any non-standard names, with the exception of things like $schema, $ref, $id, and others that have special meaning within the JSON schema specification. These would have to somehow be mapped to and from internal representations in JSONSchema when it's converted to and from a dictionary.

This came up in Altair here: vega/altair#370

Error generating schema from the vscode debug protocol

The code below reproduces the problem:

def gen_debugger_protocol():
    import os.path

    json_file = os.path.join(os.path.dirname(__file__), 'debugProtocol.json')
    if not os.path.exists(json_file):
        import requests
        req = requests.get('https://raw.githubusercontent.com/Microsoft/vscode-debugadapter-node/master/debugProtocol.json')
        assert req.status_code == 200
        with open(json_file, 'wb') as stream:
            stream.write(req.content)

    import json
    import schemapi
    
    with open(json_file, 'rb') as json_contents:
        contents = json.loads(json_contents.read())
        api = schemapi.JSONSchema(contents)
        api.write_module('debug_protocol_schema')


if __name__ == '__main__':
    gen_debugger_protocol()

The error I have is:

  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\schemapi\jsonschema.py", line 466, in write_module
    return utils.save_module(spec=self.source_tree(),
  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\schemapi\jsonschema.py", line 413, in source_tree
    schema_content = template.render(cls=self, classes=classes)
  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\jinja2\asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\jinja2\environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\jinja2\_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 12, in top-level template code
  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\schemapi\jsonschema.py", line 344, in object_code
    return trait_extractor.object_code()
  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\schemapi\trait_extractors.py", line 191, in object_code
    for ref in self.schema['allOf']]
  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\schemapi\trait_extractors.py", line 191, in <listcomp>
    for ref in self.schema['allOf']]
  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\schemapi\jsonschema.py", line 333, in trait_code
    return trait_extractor.trait_code(**kwargs)
  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\schemapi\trait_extractors.py", line 482, in trait_code
    in self.schema.wrapped_properties().items()}
  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\schemapi\trait_extractors.py", line 481, in <dictcomp>
    trait_codes = {name: Variable(prop.trait_code) for (name, prop)
  File "C:\tools\Miniconda\envs\tests_py36\lib\site-packages\schemapi\jsonschema.py", line 336, in trait_code
    "keys {0}".format(tuple(self.schema.keys())))
ValueError: No recognized trait code for schema with keys ('type', 'description')

Release 0.4

Please create a release 0.4 so the latest released code matches the documentation in readme.md.
Eg when I pip install schemapi now, the documentation does not reflect what gets installed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.