Git Product home page Git Product logo

jsonschema-markdown's Introduction

Hi there ๐Ÿ‘‹

jsonschema-markdown's People

Contributors

dependabot[bot] avatar elisiariocouto avatar pdcalado avatar vrince avatar ysmaoui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

jsonschema-markdown's Issues

Crash if no `properties`

Valid json schema can have no properties, for example, when the schema is a list of $defs.

The workaround is to add an empty properties object before calling jsonschema_markdown.generate but it generates an empty table.

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "./schema.py", line 8, in <module>
    markdown = jsonschema_markdown.generate(SCHEMAS, replace_refs=True, footer=False)
  File "./_env/lib/python3.10/site-packages/jsonschema_markdown/converter/markdown.py", line 68, in generate
    markdown += _create_definition_table(_schema, defs)
  File "./_env/lib/python3.10/site-packages/jsonschema_markdown/converter/markdown.py", line 134, in _create_definition_table
    for property_name, property_details in schema["properties"].items():
KeyError: 'properties'

I can probably do a PR if required.

Add support for typed `additionalProperties`

See https://cswr.github.io/JsonSchema/spec/objects/

This schema is currently supported:

{
    "type": "object",
    "properties": {
        "first_name": {
            "type": "string"
        },
        "last_name": {
            "type": "string"
        }
    },
    "additionalProperties": false
}

This schema is not supported since we are just logging a warning when additionalProperties is not a boolean:

{
    "type": "object",
    "properties": {
        "first_name": {
            "type": "string"
        },
        "last_name": {
            "type": "string"
        }
    },
    "additionalProperties": {
        "type": "integer"
    }
}
  • Add support for typed additionalProperties

Add support for all attributes of types `string`, `number` and `integer`

also the library does not visualize attributes of the types "string", "number", "integer"
https://cswr.github.io/JsonSchema/spec/basic_types/

but that is another topic.. not immediately related to this PR

Originally posted by @ysmaoui in #7 (comment)

At the moment, jsonschema-markdown supports the following types:

string

  • minLength
  • maxLength
  • pattern

number and integer

  • minLength
  • maxLength
  • exclusiveMinimum
  • exclusiveMaximum
  • multipleOf

Array-like parameters may end up with wrong type

In the test model, the manufactureres_config is a list of items.

The markdown should indicate that this is an array instead of bubbling up the type of the sub-schemas (in this case, it is marking the parameter as an object).

A refactor is needed.

TypeError: generate() got an unexpected keyword argument 'resolve'

I ran into a problem while trying to run the CLI version of this program.
I installed it via pip in an empty python:3.11 docker container (this felt easier for testing that using the provided image).
However, when trying to start using the command jsonschema-markdown /wd/json-schema/template/meta.json (with /wd being the directory I have mounted into the container) I kept getting this stacktrace:

root@9ba04be8da37:/# jsonschema-markdown --version
jsonschema-markdown, version 0.3.1
root@9ba04be8da37:/# jsonschema-markdown /wd/json-schema/template/meta.json
Traceback (most recent call last):
  File "/usr/local/bin/jsonschema-markdown", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/jsonschema_markdown/main.py", line 63, in cli
    markdown = jsonschema_markdown.generate(file_contents, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: generate() got an unexpected keyword argument 'resolve'

Below is the content of the schema file meta.json:

{
	"$schema": "http://json-schema.org/draft-07/schema#",
	"type": "object",
	"properties": {
		"response_id": {
		  "type": "string"
		},
		"version": {
		  "type":"string"
		},
		"kind": {
		  "type": "string"
		},
		"message": {
		  "type": "string"
		}
	},
	"required": ["kind","version"]
}

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.