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

Commit a9d6181

Browse files
committed
Fixing definitions that were no longer included
1 parent 2f50e96 commit a9d6181

File tree

5 files changed

+68
-14
lines changed

5 files changed

+68
-14
lines changed

src/parse.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@ export async function parseModels(models: IModel[], root: string): Promise<{}> {
1919
continue;
2020
}
2121

22-
if (typeof model.schema === 'string') {
23-
const fullPath = path.resolve(root, model.schema);
22+
const schema = (typeof model.schema === 'string'
23+
? await $RefParser.bundle(path.resolve(root, model.schema))
24+
: model.schema) as JSONSchema7;
2425

25-
const schema = await $RefParser.bundle(fullPath) as JSONSchema7;
26-
27-
_.assign(schemas, updateReferences(schema.definitions));
28-
29-
schemas[model.name] = updateReferences(cleanSchema(schema));
30-
}
31-
32-
if(typeof model.schema === 'object') {
33-
schemas[model.name] = updateReferences(cleanSchema(model.schema));
34-
}
26+
_.assign(schemas, updateReferences(schema.definitions), {
27+
[model.name]: updateReferences(cleanSchema(schema)),
28+
});
3529
}
3630

3731
return schemas;

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export interface IModel {
22
name: string;
33
description: string;
44
contentType: string;
5-
schema: string;
5+
schema: string | object;
66
examples: any[];
77
example: object;
88
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"definitions": {
4+
"directory": {
5+
"type": "object",
6+
"title": "Directory Schema",
7+
"properties": {
8+
"id": {
9+
"type": "string",
10+
"example": "3ba1c69c-3c81-4d6d-b304-873d898b2e3c",
11+
"format": "uuid"
12+
},
13+
"directories": {
14+
"type": "array",
15+
"items": {
16+
"$ref": "#/definitions/directory"
17+
}
18+
}
19+
},
20+
"additionalProperties": false,
21+
"required": ["id", "name", "directorys", "checklists"]
22+
}
23+
},
24+
"type": "object",
25+
"title": "Directories Response Schema",
26+
"properties": {
27+
"data": {
28+
"$ref": "#/definitions/directory"
29+
}
30+
}
31+
}

test/project/openapi.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,30 @@ components:
139139
properties:
140140
data:
141141
$ref: '#/components/schemas/folder'
142+
directory:
143+
type: object
144+
title: Directory Schema
145+
properties:
146+
id:
147+
type: string
148+
example: 3ba1c69c-3c81-4d6d-b304-873d898b2e3c
149+
format: uuid
150+
directories:
151+
type: array
152+
items:
153+
$ref: '#/components/schemas/directory'
154+
additionalProperties: false
155+
required:
156+
- id
157+
- name
158+
- directorys
159+
- checklists
160+
RecursiveResponseTwo:
161+
type: object
162+
title: Directories Response Schema
163+
properties:
164+
data:
165+
$ref: '#/components/schemas/directory'
142166
data:
143167
description: external type referenced in another schema
144168
type: object
@@ -165,7 +189,7 @@ components:
165189
info:
166190
title: ''
167191
description: ''
168-
version: a04837c6-b32a-4f0f-9c25-0c72112a4136
192+
version: ae88c557-65e0-4feb-a885-ebe66a58cca8
169193
paths:
170194
/create:
171195
post:

test/project/serverless.doc.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ documentation:
2727
contentType: application/json
2828
schema: models/RecursiveResponse.json
2929

30+
- name: RecursiveResponseTwo
31+
description: Recursive response example
32+
contentType: application/json
33+
schema: ${file(models/RecursiveResponseTwo.json)}
34+
3035
- name: ExternalTest
3136
description: External reference example
3237
contentType: application/json

0 commit comments

Comments
 (0)