elisiariocouto / jsonschema-markdown Goto Github PK
View Code? Open in Web Editor NEW๐ Generate markdown documentation based on a JSON Schema document
Home Page: https://pypi.org/project/jsonschema-markdown/
License: MIT License
๐ Generate markdown documentation based on a JSON Schema document
Home Page: https://pypi.org/project/jsonschema-markdown/
License: MIT License
HI @elisiariocouto, I have a requirement to add an extra field "examples" in the table can you please help to add it in the next release?
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.
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"
}
}
additionalProperties
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
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.
In the test case, the CarClass
class has a custom title Class
and the definition link is wrong.
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"]
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.