lbovet / docson Goto Github PK
View Code? Open in Web Editor NEWDocumentation for your JSON types
License: Apache License 2.0
Documentation for your JSON types
License: Apache License 2.0
Create an example HTML file:
<!DOCTYPE html>
<html>
<head>
<title>Docson Example</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/docson.css">
<body>
<p>START</p>
<script src="/widget.js" data-schema="/examples/schemaTest.json">
</script>
<p>END</p>
</body>
</html>
With an example Schema:
{
"id": "Invoice",
"description": "Represents the _document_ sent to the customer for payment.",
"properties": {
"customer": {
"description": "---\nWho will pay?\nNot me!\n - Run away to http://example.com/",
"type": "string",
"maxLength": 25
},
"props": {
"properties": {
"key": {
"type": "string",
"pattern": "[a-z][0-9]_"
},
"value" : {
"type": "string"
}
}
},
"dimension": {
"description": "Total dimension of the order - Lets go to [Index](/index.html) ",
"$ref": "Dimension"
}
}
}
(You may have to adjust relative paths for your setup.)
Open the page and you'll see:
Click one of the links and you'll see:
This example from the json schema spec section 7.2.3, doesn't seem to work with docson:
{
"id": "http://my.site/myschema#",
"definitions": {
"schema1": {
"id": "schema1",
"type": "integer"
},
"schema2": {
"type": "array",
"items": { "$ref": "schema1" }
}
}
}
http://json-schema.org/latest/json-schema-core.html
It looks like the id
tag in schema1
is being ignored when resolving the $ref
. This isn't apparent in the html, but you can see a 404 on the network when it tries to resolve the reference.
Here is the JSON that causes it: http://standard.open-contracting.org/schema/1__1__3/release-schema.json
In case it matters, it's a simple test page of:
<!DOCTYPE html>
<html>
<head>
<title>Docson Example</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/docson.css">
<body>
<script src="/widget.js" data-schema="/release-schema.json">
</script>
</body>
</html>
The Lockup has been seen in several browser on 2 computers.
I did some quick narrowing down and a3b582d works. b5f888e Doesn't.
That means that something in #49 / #41 might have changed something?
I don't have time to look more now, but I wanted to report it for informations sake. I will try and look more later, but I don't know when that will be.
I just pulled the latest Swagger UI code from Github and tried to integrate the latest Docson code using the instructions. I have been completely unsuccessful. It appears that the latest Swagger UI uses a new library, "swagger-client.js" instead of "swagger.js". The new swagger doesn't use SwaggerOperation.getSignature() but instead uses some new functions Model.getMockSignature() and ArrayModel.getMockSignature(). I tried doing the integration myself but I'm not familiar enough with the internal workings of either Docson or Swagger to get it to work quickly. Can anybody help?
Hi,
I try to render the following schema:
{
"type": "array",
"items": {
"anyOf": [
{"type": "string"},
{"type": "string",
"enum": ["Street", "Avenue", "Boulevard"]},
{"type": "string",
"enum": ["NW", "NE", "SW", "SE"]}
]
}
}
however I would expect something similar to rendering this "anyOf" as object property.
{
"type": "object",
"properties": {
"anyOf": [
{"type": "string"},
{"type": "string",
"enum": ["Street", "Avenue", "Boulevard"]},
{"type": "string",
"enum": ["NW", "NE", "SW", "SE"]}
]
}
}
Maybe I miss something, but I think the schema is valid. Also, the validator at http://json-schema-validator.herokuapp.com/ accepts the array for example with this data:
[
"NE","foo"
]
see #38
It's not possible to reference a primitive type using a $ref
, I'm pretty sure I did the schema right, because it works with validation tools.
Also $ref
to relative sources doesn't work, like {"$ref": "/myfolder/file.json"}
, and {"$ref": "fileutils.json"}
within that document...
It's details, I worked around by preprocessing my schemas to substitute constants in... But if this isn't a bug, maybe write it as a limitation.
By the way, thanks for an awesome documentation tool :)
Hi,
I've just found docson, and think it could be a useful tool for me - however I notice that there are a relatively high number of outstanding PRs and issues, and a high number of forks which seem to be ahead of this project.
I'm wondering if this project is no longer being supported? If so, are there any active forks which could be considered as a replacement for this one? Or could this project be moved to being a community-run one?
$ref reference is not display
Exemple schema:
{
"title": "Test ref",
"type": "object",
"properties": {
"jobs": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"oneOf": [
{ "$ref": "#/definitions/a" },
{ "$ref": "#/definitions/b" },
{ "$ref": "#/definitions/c" }
]
},
"uniqueItems": true
}
},
"required": ["jobs"],
"additionalProperties": false,
"definitions": {
"a": {
"type": "object",
"properties": {
"a1": {
"type": "boolean"
},
"a2": {
"type": "string"
}
},
"additionalProperties": false,
"required": ["a1", "a2"]
},
"b": {
"type": "object",
"properties": {
"b1": {
"type": "boolean"
},
"b2": {
"type": "string"
}
},
"additionalProperties": false,
"required": ["a1", "a2"]
},
"c": {
"type": "object",
"properties": {
"c1": {
"type": "boolean"
},
"c2": {
"type": "string"
}
},
"additionalProperties": false,
"required": ["a1", "a2"]
}
}
}
Check out if we work for beerjson/beerjson#13
Relates to #49.
@rom1504 The master branch is now in a npmsable state. Would you be willing to give back the npm docson namespace to this version of the project?
Hi,
I have a json schema which is not working fine with docson. I guess some problem with additional properties or with v7 update of json schema. Attaching the json schema for reference.
Made it txt to attach it. Convert the extension to .json to validate the docson package.
Hi,
I am integrating docson with RAML (both api-console & api-designer).
I am facing issues while rendering simple json-schemas that are only a reference to an externally defined one (ie their own json files).
I have built a simple demo app that shows my problems : https://github.com/McFoggy/docson-reference-demo.
ref
link and Load from schema
refWithId
and Load from schema
. The referenced address.json
is in 404 because loaded from a bad URLI would really appreciate some feedback in order to either establish that either I am doing something totally wrong or that I am facing a bug.
If the referenced model could not be found, perhaps you could treat it as a "type" and simply display the value (possibly in red to denote that the model cannot be expanded, although the lack of a button would probably be enough of a clue there).
Another possibility is to label it something like "Object(SomeModel)" (assuming the missing model was "SomeModel".
Is it possible to add/adapt styles to the docson iframe without also adding swagger?
Thanks
see #38
Hello!
I've tryed out docson today and it looks like a great tool!
But I've discoverd an issue (or maybe used docson wrongly?)
If I've got nested $ref in my json-schema files, I'll get the following error message:
Uncaught TypeError: Cannot convert undefined or null to object docson.js:286
Example:
This one works, it has one $ref to another schema
http://fannon.de/p/cbm/docson-master/#http://fannon.de/p/cbm/model/Standort.json
If i create yet another schema and place a $ref to model/Standort.json, it breaks:
http://fannon.de/p/cbm/docson-master/#http://fannon.de/p/cbm/form/Kunde.json
Have I done something wrong?
Is it generally a good idea to have nested schemas like that? Alternatively, I could put them all into one file and use internal refs.
Or is there a javascrit library which supports the aggregation of nested schemas, which returns a complete schema object?
Greets,
Simon
Hi I am trying to get it to work offline i.e. without running it on an HTTP Server. Is there any way of doing it right now?
Hello all,
What I can see so far is that I can submit a file path that the internals of docson will fetch and display. That's nice, but what if I wanted to operate on plain JSON code instead of JSON files? For example, if I wanted to combine an online editor with docson - that'd be awesome, indeed! (I'd use it in my http://json-schema-faker.js.org/ straight away)
So my question is - is is possible to use docson from JS code level, execute a function on a JSON object so that docson would generate DOM for that?
I am trying to create a html page for the json schemas where documentation of every schema is on a seperate Tab as below.
But the problem I am facing is the json documentation is not going into the tab, but just outside the tab
And also it keeps on appending to the existing html page.
I believe the issue is in the below lines
var element = $("
Kindly let me know how to resolve this
<title> Canonical Data Model JSON Draft 4 Schemas</title> <script src="lib/require.js"></script> <style> body {font-family: "Lato", sans-serif;}/* Style the tab */
div.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons inside the tab */
div.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of buttons on hover */
div.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
div.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
-webkit-animation: fadeEffect 1s;
animation: fadeEffect 1s;
}
/* Fade in tabs */
@-webkit-keyframes fadeEffect {
from {opacity: 0;}
to {opacity: 1;}
}
@Keyframes fadeEffect {
from {opacity: 0;}
to {opacity: 1;}
}
/* Style the close button */
.topright {
float: right;
cursor: pointer;
font-size: 20px;
}
.topright:hover {color: red;}
</style>
Schema defining the user for the logistic operations
Schema defining the Contract.
Hi --
Thanks for answering newbie question.
If you have an array of unspecified type, docson displays the following error message:
Error: Could not resolve schema array.
It should probably just say "array" in this case as the extra description probably explains why the type could not be specified or tied down to a single possibility (as in the coordinates array of a GeoJSON object -- whose definition changes depending on the value of the "type" field).
Still uses isCollectionType rather than isListType (among other issues).
Hello, I'd like to visualize the following schema, but it fails as the "patternProperties" field is ignored. Just see:
The schema used is:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Standing instance",
"type": "object",
"required": ["positions"],
"additionalProperties": false,
"properties": {
"positions": {
"type": "object",
"minProperties": 1,
"description": "Docson is unable to visualize: please read JSONSchema by clicking onto '{}'!",
"additionalProperties": false,
"patternProperties": {
"^[0-9]+$": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": ["key"],
"additionalProperties": false,
"properties": {
"key": {
"type": "integer"
}
}
}
}
}
}
}
}
Is this not supported by Docson? For validation purposes this schema just works fine with: https://github.com/fge/json-schema-validator
Please add support of required
keyword. It would be nice to have some little label near field name, that is in the 'required array'
What's really needed in the repo to make docson work ?
It would be nice to have a minimal distribution, a bit like jquery or bootstrap do.
I have part of my schema that looks like this:
"widgets": {
"type": "array",
"description": "Widgets!",
"items": {
"oneOf": [
{ "$ref" : "#/definitions/Widget1"},
{ "$ref" : "#/definitions/Widget2"},
{ "$ref" : "#/definitions/Widget3"}
]
}
}
In the documentation output, it just claims this is an array and there is no ability to click into those reference objects. Are oneOf/anyOf not supported in arrays when generating this documentation?
Docson seems to have trouble displaying enum type:
enumValue Error: Could not resolve schema MyEnum VALUE1 VALUE2 VALUE3
It clearly knows about the enum's allowed values, but sticks an error in the type field.
Perhaps it should just stick in "enum" in the type field rather than an error?
Allow examples that are data structures
If example is not present, try to build one from the properties's examples?
Put the example in its own
Hey all,
I have a feature request, and a PR pretty much ready to go if you're interested.
Use Case: We are documenting an API. The API is written in PHP and uses an awesome library to validate our output: https://github.com/justinrainbow/json-schema We have decided to make JSON Schema more central to our APIs. As opposed to the Swagger IO annotations of source code and creating documentation on how your API should work, we are using the JSON Schema we are validating against to create documentation. Use the tested result, not the hopeful result. We have our JSON Schema split amongst several files and reference them from each other as needed.
File: schema/location.json
{
"id" : "location",
"[other]":"[key/values]",
"properties": {
"alerts" : {
"type": "array",
"required" : true,
"items" : {
"$ref": "./alert.json"
}
}
}
}
The most important part is the $ref
in the above statement. It is relatively pointing to another file. This works great in justinrainbow's json-schema in PHP and allows us to create our schema spread around several files.
Is this in the JSON Spec this way? This part talks about it kind of? http://json-schema.org/latest/json-schema-core.html#rfc.section.7.2.3
I have a tweak to where the files get loaded, around line docson.js:442, interested in a PR?
Thanks!
I have been testing docson, but reached a problem of browser entering in a infinite loop, when I have cyclic references. There are a lot of events "MessageEvent".
It seems like the references are pre-fetched. Is there any way to disable this pre-fetched behavior?
If you have an array of specified type, but that type has no model definition, docson displays the following error message:
Error: Could not resolve schema array.
In this case it should probably just say "array[SpecifiedType]" as the extra description can be used to explain what this type is or where you can look to find out.
The docson model looks very squished and has scrollbars when used on input parameters.
I can't think of a very good solution for this but maybe there could be a button beside the current swagger tabs (Model, Model Schema) to popup the docson model? Maybe labeled simply "Docson Model". Maybe just replacing the "Model" tab with a button that pops up the docson model?
How about adding docson
to npm registry, so that non-bower developers may use docson?
Many people say that npm
will replace bower
soon (and bower will become useless), one may agree with it or not. Anyway, some users would appreciate publishing docson
in npm.
As of v4
of the draft, there is no direct possibility to use allOf
in combination with "additionalProperties" = false
, see here.
Currently one has to duplicate the properties with empty objects to get around this. But this makes the documentation quite ugly, see an example here. Would it be possible to check whether properties are defined in the allOf
section (of course resolving $ref
s) and omitting them?
Not sure if there is currently enough momentum behind v5
to get it published and then implemented here as well as the commonly used validators.
I have a JSON v4 schema that validates with the JSON meta-schema but causes docson to crash with an infinite recursion bug.
{
"myDate": {
"properties": {},
"type": "string",
"pattern": "([0-9][0-9][0-9][0-9])-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]).([0-9][0-9][0-9])Z",
"description": "some description"
}
}
The issue is caused by having an empty "properties" on a string. The JSON meta schema implies that all types have a default of an empty properties value. The spirit of the human readable spec seems to imply that it would be silly to add properties to a string or array or other primitive type. Since the meta-schema validates the above schema it would be nice if docson ignored the silly things.
I seem to be getting this error a lot in Chrome:
docson.js:76 Uncaught TypeError: undefined is not a function
Which seems to point to a handlebars template helper:
Handlebars.registerHelper('contains', function(arr, item, options) {;
if(arr && arr.indexOf(item) != -1) {
return options.fn(this);
}
});
But it's calling that function with an arr
of true
, making it blow up because indexOf() obviously isn't a method. It happens on the first property of my object defined in my schema, all the time. Am I missing something obvious? My JSON Schema validates as valid schema. Thanks!
See #38
loading following schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://dev.host/schema/entities/Party.json",
"title": "Party",
"type": "object",
"definitions": {
"RegionalSettings": {
"type": "object",
"properties": {
"currency": {
"type": "string"
},
"timezone": {
"type": "string"
},
"dateFormat": {
"type": "string"
},
"timeDelimiter": {
"type": "string",
"enum": [":", "-", " "]
},
"oderOfFirstLastName": {
"type": "boolean"
}
},
"required": [
"currency",
"timezone",
"dateFormat",
"timeDelimiter",
"oderOfFirstLastName"
],
"additionalProperties": false
}
},
"properties": {
"UUID": {
"type": "string"
},
"regionalSettings": {
"$ref": "#/definitions/RegionalSettings"
},
"avatar": {
"type": "string"
}
},
"required": [
"UUID"
],
"additionalProperties": false
}
as part of:
{
"$schema": "http://json-schema.org/draft-04/schema",
"id": "http://dev.host/schema/entities/User.json",
"title": "User",
"type": "object",
"definitions": {
"UserName": {
"type": "object",
"properties": {
"name": {
"type": "array",
"items": {
"allOf": [
{"$ref": "http://dev.host/schema/entities/Localizable.json"},
{"$ref": "http://dev.host/schema/entities/UserFullName.json"}
]
}
}
}
},
"UserContacts": {
"type": "object",
"properties": {
"userAdditionalContacts": {
"type": "object",
"properties": {
"mail": {"type": "string"},
"sip": {"type": "string"}
}
}
}
}
},
"allOf": [
{"$ref": "http://dev.host/schema/entities/Party.json"},
{"$ref": "#/definitions/UserName"},
{"$ref": "#/definitions/UserContacts"}
],
"additionalProperties": false
}
results in $ref: #/definitions/**
being rendered as is (string, see atached screenshot) instead of resolved object tile.
First, this project is awesome :)
Our schema has a "license" field with a lot of enums: https://tools.wmflabs.org/extreg-wos/extension.schema.json
This means that it takes up a good portion of the page: https://tools.wmflabs.org/extreg-wos/schema.html
Is there a way it could be collapsed if the list is over a certain length?
I am confused as to how to run tests for Docson (and add tests for bugs I’m trying to fix, which is my actual motivation). Here is what I tried:
npm run build
, unlike the files in public/js. There however seems to be no usable replacement for it, I cannot find an output file that is both loadable in the browser (is not a CommonJS module, unlike lib/index.js) and exports the docson
API without already using it (unlike public/js/webpage.js).npm -g install nightwatch
, which is not mentioned), I get the message Error: Cannot read test source location: /Users/cwalther/Documents/json-schema-tools/docson/nightwatch
. I suspect this is a sign of bitrot too, since a folder nightwatch has existed once, before it was renamed to integration, and therefore stop searching in this direction.node_modules/.bin/jest
, which I try on a whim based on the presence of a jest.config.js. When run like that, it gets stuck with one test suite passing and the other still running (I think I have a fix for that and will follow up with a pull request), but when run individually (node_modules/.bin/jest integration/widget.test.js
, node_modules/.bin/jest integration/basic.test.js
), they pass. So it that the proper way?Could any outdated things please be removed from the repository, or clearly marked as outdated?
If there is a supported automated way of running tests, I would also suggest naming it as scripts.test in package.json so that no detective work is required to find it.
<script src="/js/widget.js"
data-schema="schema1.json">
</script>
<script src="/js/widget.js"
data-schema="schema2.json">
</script>
Fails with:
Uncaught Error: only one instance of babel-polyfill is allowed
Hello,
Thank you for the tool. It produces the best schema docs out there!
But I have a problem: I don't want my doc website to accept a schema as a parameter and then generate its doc dynamically. Instead, I want to have some CLI tool (nodejs tool maybe?) that accepts the schema, and generates a static website out of it. Would there be a way to refactor your code to make it do just that? I don't think it is too much of a hassle, what do you guys think?
one other option that does not require refactoring is to have a (docker image maybe?) that hosts the app on some server, and then communicates with it using Selenium (web browser simulator) and provides it with the Schema, then stores the generated page as a static website.
The reason why I am interested in a static page is that I have a humongous schema, and the tool takes about 5 seconds to generate it each time a user opens the docs. But if it were static, it would have been much faster.
I am looking for minimal support of the V5 proposal. For example, I would love to be able to handle $data inside minimum, maximum validations.
Is anyone looking at V5 support, in general?
Currently enums are displayed as several SPAN elements, which will print each value separated by spaces and will wrap accordingly.
But when there are many values this is hard to read.
Could the HTML/CSS representation of enums be displayed as one value per line for easier reading?
Maybe use UL instead?
I'm getting that error trying to use docson on that schema https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/protocol/protocol_schema.json
Any clue why ?
Edit:
Oh I bet that's because that schema is recursive.
Docson should be able to handle that somehow though...
Maybe there is an option to limit the recursion level ?
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.