Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Error generating schema from the vscode debug protocol #5

Closed
fabioz opened this issue Apr 18, 2018 · 4 comments
Closed

Error generating schema from the vscode debug protocol #5

fabioz opened this issue Apr 18, 2018 · 4 comments

Comments

@fabioz
Copy link

fabioz commented Apr 18, 2018

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')
@jakevdp
Copy link
Member

jakevdp commented Apr 19, 2018

Hi – I'm planning on deprecating this version of schemapi, and updating to a version not based on traitlets (see https://github.com/altair-viz/altair/tree/master/tools/schemapi)

I didn't know anyone was using this... what's your use-case?

@fabioz
Copy link
Author

fabioz commented Apr 20, 2018

Well, I was investigating a way to create objects from/to json messages (to adapt the pydevd debugger to the vscode protocol).

In the end I didn't really find anything and decided to roll my own code generator as the schema is actually simple (but decided on reporting the bug since it seems like it should work, although I won't be using it given that it didn't really work out of the box, so, feel free to close it if you don't think it's worth it).

@jakevdp
Copy link
Member

jakevdp commented Apr 20, 2018

Thanks, makes sense.

For what it's worth, it was issues like this one that led me to abandon the traitlets-based approach in the end. I couldn't see any way to fix them given the constraints of traitlets and the assumptions of jsonschema.

@jakevdp
Copy link
Member

jakevdp commented Apr 20, 2018

But the updated version within altair works quite well, if you want to try it.

@jakevdp jakevdp closed this as completed Apr 20, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants