Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements #67. Add an else clause to allow a nested object property #90

Merged
merged 8 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [Extensible](./extensible.schema.md) – `https://example.com/schemas/extensible` (Unknown)
* [Identifiable](./identifiable.schema.md) – `https://example.com/schemas/identifiable` (Unknown)
* [Join Types](./join.schema.md) – `https://example.com/schemas/join` (Unknown)
* [Nested Object](./nestedobj.schema.md) – `https://example.com/schemas/nestedobject` (Unknown)
* [Pattern Properties](./pattern.schema.md) – `https://example.com/schemas/pattern` (Unknown)
* [Simple](./simple.schema.md) – `https://example.com/schemas/simple` (Unknown)
* [Simple Types](./simpletypes.schema.md) – `https://example.com/schemas/simpletypes` (Unknown)
Expand Down
93 changes: 93 additions & 0 deletions examples/docs/nestedobj.schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
template: reference
foo: bar
---

# Nested Object Schema

```
https://example.com/schemas/nestedobject
```


| [Abstract](../abstract.md) | Extensible | [Status](../status.md) | Identifiable | Custom Properties | Additional Properties | Defined In |
|----------------------------|------------|------------------------|--------------|-------------------|-----------------------|------------|
| Can be instantiated | No | Experimental | No | Forbidden | Forbidden | [nestedobj.schema.json](nestedobj.schema.json) |

# Nested Object Properties

| Property | Type | Required | Nullable | Defined by |
|----------|------|----------|----------|------------|
| [settings](#settings) | `object` | Optional | No | Nested Object (this schema) |

## settings

settings

`settings`

* is optional
* type: `object`
* defined in this schema

### settings Type


`object` with following properties:


| Property | Type | Required |
|----------|------|----------|
| `collaborators`| object | Optional |



#### collaborators

collaborators

`collaborators`

* is optional
* type: `object`

##### collaborators Type


`object` with following properties:


| Property | Type | Required |
|----------|------|----------|
| `id`| string | Optional |



#### id


`id`

* is optional
* type: `string`

##### id Type


`string`
















29 changes: 29 additions & 0 deletions examples/generated-schemas/nestedobj.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$id": "https://example.com/schemas/nestedobject",
"$schema": "http://json-schema.org/draft-07/schema",
"title": "Nested Object",
"type": "object",
"properties": {
"settings": {
"description": "settings",
"type": "object",
"properties": {
"collaborators": {
"description": "collaborators",
"type": "object",
"patternProperties": {
".*": {
"type": "string"
}
},
"properties": {
"id": {
"type": "string"
}
}
}
}
}
},
"additionalProperties": false
}
29 changes: 29 additions & 0 deletions examples/schemas/nestedobj.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$id": "https://example.com/schemas/nestedobject",
"$schema": "http://json-schema.org/draft-07/schema",
"title": "Nested Object",
"type": "object",
"properties": {
"settings": {
"description": "settings",
"type": "object",
"properties": {
"collaborators": {
"description": "collaborators",
"type": "object",
"patternProperties": {
".*": {
"type": "string"
}
},
"properties": {
"id": {
"type": "string"
}
}
}
}
}
},
"additionalProperties": false
}
1 change: 1 addition & 0 deletions spec/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [Extensible](./extensible.schema.md) – `https://example.com/schemas/extensible` (Unknown)
* [Identifiable](./identifiable.schema.md) – `https://example.com/schemas/identifiable` (Unknown)
* [Join Types](./join.schema.md) – `https://example.com/schemas/join` (Unknown)
* [Nested Object](./nestedobj.schema.md) – `https://example.com/schemas/nestedobject` (Unknown)
* [Pattern Properties](./pattern.schema.md) – `https://example.com/schemas/pattern` (Unknown)
* [Simple](./simple.schema.md) – `https://example.com/schemas/simple` (Unknown)
* [Simple Types](./simpletypes.schema.md) – `https://example.com/schemas/simpletypes` (Unknown)
Expand Down
93 changes: 93 additions & 0 deletions spec/examples/nestedobj.schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
template: reference
foo: bar
---

# Nested Object Schema

```
https://example.com/schemas/nestedobject
```


| [Abstract](../abstract.md) | Extensible | [Status](../status.md) | Identifiable | Custom Properties | Additional Properties | Defined In |
|----------------------------|------------|------------------------|--------------|-------------------|-----------------------|------------|
| Can be instantiated | No | Experimental | No | Forbidden | Forbidden | [nestedobj.schema.json](nestedobj.schema.json) |

# Nested Object Properties

| Property | Type | Required | Nullable | Defined by |
|----------|------|----------|----------|------------|
| [settings](#settings) | `object` | Optional | No | Nested Object (this schema) |

## settings

settings

`settings`

* is optional
* type: `object`
* defined in this schema

### settings Type


`object` with following properties:


| Property | Type | Required |
|----------|------|----------|
| `collaborators`| object | Optional |



#### collaborators

collaborators

`collaborators`

* is optional
* type: `object`

##### collaborators Type


`object` with following properties:


| Property | Type | Required |
|----------|------|----------|
| `id`| string | Optional |



#### id


`id`

* is optional
* type: `string`

##### id Type


`string`
















2 changes: 1 addition & 1 deletion spec/lib/integrationTest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Compare results', () => {
ls.on('close', code => {
expect(code).toEqual(0);
const files = readdirSync('./spec/examples').filter(item => !(/(^|\/)\.[^\/\.]/g).test(item));
expect(files.length).toEqual(21);
expect(files.length).toEqual(22);

files.forEach(file => {
if (statSync('./spec/examples/' + file).isFile()) {
Expand Down
5 changes: 4 additions & 1 deletion templates/md/nested-property.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#### <%=name %>
<% if (schema.title) { %>##### <%= schema.title %><% } %>


<% if (schema.description) { %>
<%- (""+schema.description).replace(/\n/g, '\n\n') %>
<% } %>


`<%=name %>`
Expand Down Expand Up @@ -44,6 +45,8 @@ The value of this property **must** be equal to one of the [known values below](
<%- include("number-type",{schema:schema,_:_}) %>
<% } else if (schema.type==="boolean") { %>
<%- include("boolean-type",{schema:schema,_:_}) %>
<% } else if (schema.type==="object") { %>
<%- include("object-type",{schema:schema,_:_}) %>
<% } else if (schema.type==="array") { %>
<%- include("array-type",{schema:schema,_:_,nested:false,ejs:ejs}) %>
<% } else if (schema.$ref!==undefined) { %>
Expand Down