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

#14 basic array handling

parent f0c4d441
Branches
Tags
No related merge requests found
......@@ -7,6 +7,7 @@
## /
* [Abstract](./abstract.schema.md)`https://example.com/schemas/abstract`
* [Arrays](./arrays.schema.md)`https://example.com/schemas/arrays`
* [Constant Types](./constants.schema.md)`https://example.com/schemas/constants`
* [Custom](./custom.schema.md)`https://example.com/schemas/custom`
* [Custom](./deepextending.schema.md)`https://example.com/schemas/deepextending`
......
---
template: reference
foo: bar
---
# Arrays Schema
```
https://example.com/schemas/arrays
```
This is an example schema with examples for multiple array types and their constraints.
| Abstract | Extensible | Custom Properties | Defined In |
|----------|------------|-------------------|------------|
| Can be instantiated | No | Forbidden | [arrays.schema.json](arrays.schema.json) |
# Arrays Properties
| Property | Type | Required | Defined by |
|----------|------|----------|------------|
| [list](#list) | `string[]` | Optional | Arrays (this schema) |
| [intlist](#intlist) | `integer[]` | Optional | Arrays (this schema) |
## list
This is an array
`list`
* is optional
* type: `string[]`
* defined in this schema
### list Type
Unknown type `array`.
```json
{
"type": "array",
"description": "This is an array",
"items": {
"type": "string",
"simpletype": "`string`"
},
"simpletype": "`string[]`"
}
```
## intlist
This is an array
`intlist`
* is optional
* type: `integer[]`
* defined in this schema
### intlist Type
Unknown type `array`.
```json
{
"type": "array",
"description": "This is an array",
"items": {
"type": "integer",
"simpletype": "`integer`"
},
"simpletype": "`integer[]`"
}
```
......@@ -19,7 +19,7 @@ This is an example schema with examples for properties with constant values
| Property | Type | Required | Defined by |
|----------|------|----------|------------|
| [hello](#hello) | `const` | **Required** | Constant Types (this schema) |
| [hello](#hello) | `const` | Optional | Constant Types (this schema) |
## hello
......
......@@ -20,7 +20,7 @@ It is imported using `allOf` and `$ref`.
| Property | Type | Required | Defined by |
|----------|------|----------|------------|
| [id](#id) | `string` | **Required** | Definitions (this schema) |
| [id](#id) | `string` | Optional | Definitions (this schema) |
## id
......
......@@ -19,7 +19,7 @@ This is an example schema with examples for properties with enum values
| Property | Type | Required | Defined by |
|----------|------|----------|------------|
| [hello](#hello) | `enum` | **Required** | Enumerated (this schema) |
| [hello](#hello) | `enum` | Optional | Enumerated (this schema) |
## hello
......
......@@ -37,7 +37,7 @@ This is an example schema with *multiple* examples. Too many examples? There can
| Property | Type | Required | Defined by |
|----------|------|----------|------------|
| [foo](#foo) | `string` | Optional | Examples (this schema) |
| [bar](#bar) | `string` | **Required** | Examples (this schema) |
| [bar](#bar) | `string` | Optional | Examples (this schema) |
## foo
......
{
"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/arrays",
"title": "Arrays",
"type": "object",
"description": "This is an example schema with examples for multiple array types and their constraints.",
"properties": {
"list": {
"type": "array",
"description": "This is an array",
"items": {
"type": "string"
}
},
"intlist": {
"type": "array",
"description": "This is an array",
"items": {
"type": "integer"
}
}
}
}
\ 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/arrays",
"title": "Arrays",
"type": "object",
"description": "This is an example schema with examples for multiple array types and their constraints.",
"properties": {
"list": {
"type":"array",
"description": "This is an array",
"items": {
"type": "string"
}
},
"intlist": {
"type":"array",
"description": "This is an array",
"items": {
"type": "integer"
}
}
}
}
......@@ -67,7 +67,7 @@ function stringifyExamples(examples) {
if (typeof examples === 'string') {
examples = [ examples ];
}
console.log(examples);
//console.log(examples);
return examples.map(example => {
return JSON.stringify(example, null, 2);
});
......@@ -102,7 +102,17 @@ function simpletype(prop) {
} else if (type==='object') {
prop.simpletype = '`object`';
} else if (type==='array') {
prop.simpletype = '`array`';
if (prop.items!==undefined) {
const innertype = simpletype(prop.items);
if (innertype.simpletype==='complex') {
prop.simpletype = '`array`';
} else {
prop.simpletype = innertype.simpletype.replace(/`$/, '[]`');
}
console.log();
} else {
prop.simpletype = '`array`';
}
} else {
prop.simpletype = 'complex';
}
......@@ -155,8 +165,6 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen
}
}
console.log(requiredProperties(schema.properties, schema.required));
multi = multi.map(([ template, context ]) => {
return [
path.join(__dirname, '../templates/md/' + template),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment