Giter Site home page Giter Site logo

json-schema-codegen's People

Contributors

john-drumright-nsc avatar pearmaster 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

Watchers

 avatar  avatar  avatar  avatar  avatar

json-schema-codegen's Issues

Arrays containing object items

If an array schema directly contains an object schema as its items, then it won't always codegen.

This doesn't work:

type: array
items:
  type: object
  properties:
    foo:
      type: integer
  required: [foo]

This does work:

type: array
items:
  $ref: "../theObjectSchema"

anyOf allows zero or more

According to the JSON-Schema spec, an anyOf schema combinator enforces one or more of the specified schemas. Currently, in this project anyOf allows for zero or more.

The consequence for this is that the code will have a false positive (accepts without error when it should throw an error) when zero sub-schemas are provided.

Python template fails when using kwargs only

Template is here

    def __init__(self, data=None, **kwargs):
        """Initialization for the {{Name}} object.
        It can be initialized with an object, or by passing each
        object property as a keyword argument.
        """
        new_data = {}
        {%-for propName, propSchema in schema.properties.items()%}
        try:
            prop = data["{{propName}}"] if ("{{propName}}" in data) else kwargs["{{propName}}"]

The last line should read:

            prop = data["{{propName}}"] if (data is not None and "{{propName}}" in data) else kwargs["{{propName}}"]

Otherwise when data is None, it will fail every time.

Generating from schema is very difficult to use

Please update examples, I have no idea how to use the root argument with generator.Generate. Also your examples with Python are very difficult to use - I'm not sure which is the class_name and which is filename_base.

GPL license means that generated code is also licensed under GPL

Hi there!

My understanding is that the output of json-schema-codegen constitutes a derivative work of the templates in the source repository and the templates are licensed under GPL. That makes the generated code also fall under the GPL.

And even if I write my own templates (licensed under a different license), I am not convinced that this will hold water legally. Or that the templates would not constitute a derivative work themselves and fall under GPL themselves.

My questions is:

When you chose GPL as license, were you aware that that choice will also transmit to the generated code? Was this a conscious decision?

In case this was a deliberate decision, would you consider adding a Bison-style exception[1] to json-schema-codegen, or change the license to a more permissive, non-copyleft license like MIT?

Thanks a lot for your work on json-schema-codegen and your consideration of this issue!

Tobias

[1] https://spdx.org/licenses/Bison-exception-2.2.html

Install via pip failing for jacobsjinjatoo

When installing via pip install json-schema-codegen, the following errors occur

ERROR: Could not find a version that satisfies the requirement jacobsjinjatoo (from json-schema-codegen->-r requirements.txt (line 1)) (from versions: none)
ERROR: No matching distribution found for jacobsjinjatoo (from json-schema-codegen->-r requirements.txt (line 1))

Appears jacobsjinjatoo project is listed as jacobs-jinja-too in PyPI

jinja2.exceptions.UndefinedError: 'None' has no attribute 'py_include_statement'

Hi,
I'm trying to parse JSON Schema for OpenAPI 3 specification, and I'm getting a most cryptic error coming somewhere from jinja or a template.

Any hints on what could cause the problem?

  File "/Users/matte/Documents/Projects/lapis/src/lapis/__main__.py", line 9, in main
    generator.Generate(yaml.safe_load(fp), 'Example', 'example', 'example')

  File "/Users/matte/Library/Caches/pypoetry/virtualenvs/lapis-4Aax896p-py3.10/lib/python3.10/site-packages/jsonschemacodegen/python.py", line 51, in Generate
    return generator.render_template(template_name="file.py.jinja2", output_name="{}.py".format(filename_base), resolver=self.resolver, **args)

  File "/Users/matte/Library/Caches/pypoetry/virtualenvs/lapis-4Aax896p-py3.10/lib/python3.10/site-packages/jacobsjinjatoo/templator.py", line 92, in render_template
    rendered = template.render(kwargs)

  File "/Users/matte/Library/Caches/pypoetry/virtualenvs/lapis-4Aax896p-py3.10/lib/python3.10/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()

  File "/Users/matte/Library/Caches/pypoetry/virtualenvs/lapis-4Aax896p-py3.10/lib/python3.10/site-packages/jinja2/environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)

  File "/Users/matte/Library/Caches/pypoetry/virtualenvs/lapis-4Aax896p-py3.10/lib/python3.10/site-packages/jsonschemacodegen/templates/python/file.py.jinja2", line 8, in <module>
    {{importer.GetImports(resolver, schema, includes)}}

  File "/Users/matte/Library/Caches/pypoetry/virtualenvs/lapis-4Aax896p-py3.10/lib/python3.10/site-packages/jinja2/runtime.py", line 828, in _invoke
    rv = self._func(*arguments)

  File "/Users/matte/Library/Caches/pypoetry/virtualenvs/lapis-4Aax896p-py3.10/lib/python3.10/site-packages/jsonschemacodegen/templates/python/import.py.jinja2", line 67, in <module>
    {%-            do includes.append(resolver.py_include_statement(prop['$ref']))-%}

  File "/Users/matte/Library/Caches/pypoetry/virtualenvs/lapis-4Aax896p-py3.10/lib/python3.10/site-packages/jinja2/utils.py", line 84, in from_obj
    if hasattr(obj, "jinja_pass_arg"):

jinja2.exceptions.UndefinedError: 'None' has no attribute 'py_include_statement'

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.