Skip to content

Commit

Permalink
Merge branch 'npm-migration'
Browse files Browse the repository at this point in the history
yanick committed Jul 19, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents d6db527 + 4405fac commit 0f5a1d6
Showing 55 changed files with 60,436 additions and 95 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets":[ "env" ]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
docson.iml
/nbproject
node_modules
7 changes: 7 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Revision history for docson

## NEXT

* NPMize the project. [GH#38]
* Add 'docson' cli program. [GH#62]



## v1.1.0

### Enhancements
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -18,6 +18,27 @@ Give Docson a JSON schema and it will generate a [beautiful documentation](http:

## Usage

### Via cli tool

$ docson -d ./schemas/
server ready and running at localhost:3000

# and then...
firefox http://localhost:3000/schemas/ship.json

### As a webpage widget

To include a Docson schema documentations on any page (wiki, ...) without worrying about messing up with javascript libraries and cross-origin issues:

* Install Docson somewhere as described above.
* Place the following `script` tags in the including page, nothing else is needed:

<script src="http://somewhere/path-to-docson/public/js/widget.js" data-schema="/path-to/schema.json">
</script>


### Add to a webpage

* Open [index.html](http://lbovet.github.io/docson/index.html) and enter the schema path in the form field.
* Or give the schema path directly as hash parameter: [index.html#/docson/examples/example.json](http://lbovet.github.io/docson/index.html#/docson/examples/example.json)

@@ -31,19 +52,6 @@ For example, [index.html#/typson/example/invoice/line.ts$InvoiceLine](http://lbo

You need to install [Typson](https://github.com/lbovet/typson) by yourself on your server. It must be in a directory named `typson` located at the same level as the `docson` directory.

## Widget

To include a Docson schema documentations on any page (wiki, ...) without worrying about messing up with javascript libraries and cross-origin issues:

* Install Docson somewhere as described above.
* Place the following `script` tags in the including page, nothing else is needed:

```html
<script src="http://somewhere/path-to-docson/widget.js" data-schema="/path-to-schema">
</script>
```

See the [widget example](http://jsfiddle.net/3kXu2/3/) on jsfiddle.

## Swagger

11 changes: 11 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# github.com/go-task/task

version: '2'

vars:
GREETING: Hello, World!

tasks:
build-widget:
cmds:
- webpack
File renamed without changes.
4 changes: 2 additions & 2 deletions nightwatch/basic.js → integration/basic.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const c2x = require( 'css2xpath' );
let static_app = require( '../lib/server' );
let static_app = require( 'src/server' )({ directory: '.' });
let server;

const rootUrl = "http://localhost:3000/index.html";
const rootUrl = "http://localhost:3000/public/index.html";

module.exports = {
before: done => {
105 changes: 105 additions & 0 deletions integration/basic.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const puppeteer = require('puppeteer');
const path = require('path');

jest.setTimeout(500000);

const server = new Promise( resolve => {
let app = require( '../src/server' )({ directory: path.join( __dirname, '..' ) });
let server;
server = app.listen( 3000, () => resolve(server) );
}).catch( e => console.log(e) );

const browser = puppeteer.launch({ headless: true });

const rootUrl = "http://localhost:3000/public/index.html";

beforeAll( async () => { await server }, 50000 );
afterAll( async () => {
( await server ).close();
( await browser ).close();
} );

test( 'relative paths', async () => {
const page = await ( await browser ).newPage();

await page.goto( rootUrl + "#/integration/schemas/relative.json");

await page.waitFor('//*[@id="doc"]/div[1]/div[3]/div[2]/div[2]/div/div[1]/div[3]/div[2]/div[2]/div/div[1]/div[3]/div[2]/div[1]/div[3]/p');

let text = await page.evaluate( () => document.querySelector('p').innerText );

expect(text).toMatch( 'a baz string' );


await page.close();

});

test('resolve #definitions in non-root schema', async () => {
const page = await ( await browser ).newPage();

await page.goto( rootUrl + "#/integration/schemas/def-non-root/User.json");

await page.waitFor(5000);

await expect(
page.evaluate( () => Array.from(document.querySelectorAll('.property-name').values()).map( s => s.innerText ) )
).resolves.toContain( 'oderOfFirstLastName' );

await page.close();

});

test('local schema, absolute path', async () => {
const page = await ( await browser ).newPage();

await page.goto( rootUrl + "#/integration/schemas/local-absolute/main.json");

await page.waitFor(5000);

await expect(
page.evaluate( () => Array.from(document.querySelectorAll('.desc').values()).map( s => s.innerText ) )
).resolves.toContain( "a foo number\n" );

await page.close();

});

test('recursive schemas', async () => {
const page = await ( await browser ).newPage();

await page.goto( rootUrl + "#/integration/schemas/recursive/circle.json");

await page.waitFor(5000);

await expect(
page.evaluate( () => Array.from(document.querySelectorAll('.desc').values()).map( s => s.innerText ) )
).resolves.toContain( "circular reference\n" );

await page.close();
});


test('recursive schemas, part II', async () => {
const page = await ( await browser ).newPage();

await page.goto( rootUrl + "#/integration/schemas/recursive/within_schema.json");
await page.waitFor(5000);

let results = await
page.evaluate( () => Array.from(document.querySelectorAll('p').values()).map( s => s.innerText ) );

expect(results).toContain( 'circular definitions' );
});

test('pretty big schema', async () => {
const page = await ( await browser ).newPage();

await page.goto( rootUrl + "#/integration/schemas/release-schema.json");
await page.waitFor( '//*[@id="doc"]/div[1]/div[3]/div[12]/div[2]/div/div[1]/div[3]/div[11]/div[1]/div[3]/p');

let results = await
page.evaluate( () => Array.from(document.querySelectorAll('p').values()).map( s => s.innerText ) );

expect(results).toContain( 'All documents and attachments related to the contract, including any notices.' );
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions integration/schemas/local-absolute/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "object",
"properties": {
"foo": { "$ref": "/integration/schemas/local-absolute/foo.json" }
}
}

File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 0f5a1d6

Please sign in to comment.