Skip to content
Snippets Groups Projects
Commit 16b75ac6 authored by Lars Trieloff's avatar Lars Trieloff
Browse files

Add support for examples #14

parent 86438468
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
* [Custom](./deepextending.schema.md)`https://example.com/schemas/deepextending` * [Custom](./deepextending.schema.md)`https://example.com/schemas/deepextending`
* [Definitions](./definitions.schema.md)`https://example.com/schemas/definitions` * [Definitions](./definitions.schema.md)`https://example.com/schemas/definitions`
* [Example](./example.schema.md)`https://example.com/schemas/example` * [Example](./example.schema.md)`https://example.com/schemas/example`
* [Examples](./examples.schema.md)`https://example.com/schemas/examples`
* [Extending](./extending.schema.md)`https://example.com/schemas/extending` * [Extending](./extending.schema.md)`https://example.com/schemas/extending`
* [Extensible](./extensible.schema.md)`https://example.com/schemas/extensible` * [Extensible](./extensible.schema.md)`https://example.com/schemas/extensible`
* [Simple](./simple.schema.md)`https://example.com/schemas/simple` * [Simple](./simple.schema.md)`https://example.com/schemas/simple`
......
...@@ -15,4 +15,9 @@ This is an example schema with examples. Too many examples? There can never be t ...@@ -15,4 +15,9 @@ This is an example schema with examples. Too many examples? There can never be t
|----------|------------|-------------------|------------| |----------|------------|-------------------|------------|
| Can be instantiated | No | Forbidden | [example.schema.json](example.schema.json) | | Can be instantiated | No | Forbidden | [example.schema.json](example.schema.json) |
## Example Example
```json
{"foo":"bar","bar":"baz"}
```
--- ---
\ No newline at end of file
---
template: reference
foo: bar
---
# Examples Schema
```
https://example.com/schemas/examples
```
This is an example schema with *multiple* examples. Too many examples? There can never be too many examples!
| Abstract | Extensible | Custom Properties | Defined In |
|----------|------------|-------------------|------------|
| Can be instantiated | No | Forbidden | [examples.schema.json](examples.schema.json) |
## Examples Examples
```json
{"foo":"bi","bar":"bu"}
```
```json
{"foo":"zip","bar":"zap"}
```
---
\ No newline at end of file
{
"meta:license": [
"Copyright 2017 Adobe Systems Incorporated. All rights reserved.",
"This file is licensed to you under the Apache License, Version 2.0 (the 'License');",
"you may not use this file except in compliance with the License. You may obtain a copy",
"of the License at http://www.apache.org/licenses/LICENSE-2.0"
],
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "https://example.com/schemas/examples",
"title": "Examples",
"type": "object",
"description": "This is an example schema with *multiple* examples. Too many examples? There can never be too many examples!",
"properties": {
"foo": {
"type": "string",
"description": "A simple string.",
"meta:example": "bar"
},
"bar": {
"type": "string",
"description": "A simple string.",
"meta:example": [
"bar",
"baz"
]
}
},
"examples": [
{
"foo": "bi",
"bar": "bu"
},
{
"foo": "zip",
"bar": "zap"
}
]
}
\ No newline at end of file
{
"foo": "bi",
"bar": "bu"
}
\ No newline at end of file
{
"foo": "zip",
"bar": "zap"
}
\ No newline at end of file
...@@ -62,6 +62,17 @@ function flatten(dependencies) { ...@@ -62,6 +62,17 @@ function flatten(dependencies) {
return deps; return deps;
} }
function stringifyExamples(examples) {
if (examples) {
console.log(examples);
return examples.map(example => {
return JSON.stringify(example, 2);
});
} else {
return false;
}
}
const generateMarkdown = function(filename, schema, schemaPath, outDir, dependencyMap) { const generateMarkdown = function(filename, schema, schemaPath, outDir, dependencyMap) {
var ctx = { var ctx = {
schema: schema, schema: schema,
...@@ -83,6 +94,7 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen ...@@ -83,6 +94,7 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen
props: schemaProps(schema, schemaPath, filename) } ], props: schemaProps(schema, schemaPath, filename) } ],
//[ 'divider.ejs', null ], //[ 'divider.ejs', null ],
//[ 'topSchema.ejs', ctx ], //[ 'topSchema.ejs', ctx ],
[ 'examples.ejs', { examples: stringifyExamples(schema.examples), title: schema.title } ],
[ 'divider.ejs', null ] [ 'divider.ejs', null ]
].map(([ template, context ]) => { ].map(([ template, context ]) => {
return [ return [
......
<% /**
* Copyright 2017 Adobe Systems Incorporated. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*/ %><% if (examples && examples.length == 1) { %>
## <%=title %> Example
```json
<%- examples[0] %>
```
<% } else if (examples && examples.length > 1) { %>
## <%=title %> Examples
<% _.forEach(examples, example => { %>
```json
<%- example %>
```
<% }); %>
<% } %>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment