Skip to content
This repository was archived by the owner on Dec 10, 2021. It is now read-only.

Commit 2f50e96

Browse files
committed
Add example models for external references
1 parent efb0b85 commit 2f50e96

File tree

6 files changed

+83
-2
lines changed

6 files changed

+83
-2
lines changed

src/DefinitionGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as uuid from 'uuid';
44

55
import { IDefinition, IDefinitionConfig, IOperation, IParameterConfig, IServerlessFunctionConfig } from './types';
66
import { cleanSchema } from './utils';
7-
import { parseModels } from './SchemaBuilder';
7+
import { parseModels } from './parse';
88
import _ = require('lodash');
99

1010
export class DefinitionGenerator {

test/project/models/Common.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"definitions": {
4+
"external": {
5+
"description": "external type referenced in another schema",
6+
"type": "object",
7+
"properties": {
8+
"one": {
9+
"type": "string",
10+
"format": "uri"
11+
},
12+
"two": {
13+
"type": "string"
14+
}
15+
},
16+
"additionalProperties": true
17+
}
18+
}
19+
}

test/project/models/ExternalOne.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"title": "ExternalTest",
5+
"definitions": {
6+
"data": {
7+
"$ref": "Common.json#/definitions/external"
8+
}
9+
},
10+
"properties": {
11+
"data": {
12+
"$ref": "#/definitions/data"
13+
}
14+
}
15+
}

test/project/models/ExternalTwo.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"title": "ExternalTest2",
5+
"definitions": {
6+
"data": {
7+
"$ref": "Common.json#/definitions/external"
8+
}
9+
},
10+
"properties": {
11+
"data": {
12+
"$ref": "#/definitions/data"
13+
}
14+
}
15+
}

test/project/openapi.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,33 @@ components:
139139
properties:
140140
data:
141141
$ref: '#/components/schemas/folder'
142+
data:
143+
description: external type referenced in another schema
144+
type: object
145+
properties:
146+
one:
147+
type: string
148+
format: uri
149+
two:
150+
type: string
151+
additionalProperties: true
152+
ExternalTest:
153+
type: object
154+
title: ExternalTest
155+
properties:
156+
data:
157+
$ref: '#/components/schemas/data'
158+
ExternalTest2:
159+
type: object
160+
title: ExternalTest2
161+
properties:
162+
data:
163+
$ref: '#/components/schemas/data'
142164
securitySchemes: {}
143165
info:
144166
title: ''
145167
description: ''
146-
version: 09299b07-9e3d-4b1c-949e-924a11084b28
168+
version: a04837c6-b32a-4f0f-9c25-0c72112a4136
147169
paths:
148170
/create:
149171
post:

test/project/serverless.doc.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,13 @@ documentation:
2626
description: Recursive response example
2727
contentType: application/json
2828
schema: models/RecursiveResponse.json
29+
30+
- name: ExternalTest
31+
description: External reference example
32+
contentType: application/json
33+
schema: models/ExternalOne.json
34+
35+
- name: ExternalTest2
36+
description: External reference example 2
37+
contentType: application/json
38+
schema: models/ExternalTwo.json

0 commit comments

Comments
 (0)