serverless-openapi-documenter 0.0.121 → 0.0.124-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/openapi.json +1222 -0
- package/package.json +4 -4
- package/src/definitionGenerator.js +49 -39
- package/src/schemaHandler.js +84 -47
- package/test.js +204 -0
- package/test2.js +146 -0
- package/test3.js +29 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "serverless-openapi-documenter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.124-beta.1",
|
|
4
4
|
"description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"license": "MIT",
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@apidevtools/json-schema-ref-parser": "^9.1.0",
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
52
|
+
"@usebruno/converters": "^0.16.0",
|
|
53
|
+
"@redocly/openapi-core": "^1.34.5",
|
|
54
54
|
"chalk": "^4.1.2",
|
|
55
55
|
"js-yaml": "^4.1.1",
|
|
56
56
|
"json-schema-for-openapi": "^0.5.0",
|
|
57
|
-
"openapi-to-postmanv2": "^
|
|
57
|
+
"openapi-to-postmanv2": "^6.0.0",
|
|
58
58
|
"uuid": "^11.1.0"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
@@ -167,11 +167,12 @@ class DefinitionGenerator {
|
|
|
167
167
|
|
|
168
168
|
if (documentation.contact) {
|
|
169
169
|
const contactObj = {};
|
|
170
|
-
|
|
170
|
+
|
|
171
|
+
if (documentation.contact.name) contactObj.name = documentation.contact.name;
|
|
171
172
|
|
|
172
173
|
if (documentation.contact.url) contactObj.url = documentation.contact.url;
|
|
173
174
|
|
|
174
|
-
contactObj.email = documentation.contact.email
|
|
175
|
+
if (documentation.contact.email) contactObj.email = documentation.contact.email;
|
|
175
176
|
|
|
176
177
|
const extendedSpec = this.extendSpecification(documentation.contact);
|
|
177
178
|
|
|
@@ -591,7 +592,9 @@ class DefinitionGenerator {
|
|
|
591
592
|
obj.headers = corsHeaders;
|
|
592
593
|
addHeaders(owaspHeaders);
|
|
593
594
|
} else {
|
|
594
|
-
|
|
595
|
+
if (Object.keys(owaspHeaders).length) {
|
|
596
|
+
obj.headers = owaspHeaders;
|
|
597
|
+
}
|
|
595
598
|
}
|
|
596
599
|
}
|
|
597
600
|
|
|
@@ -677,10 +680,13 @@ class DefinitionGenerator {
|
|
|
677
680
|
|
|
678
681
|
async createRequestBody(requestBodyDetails) {
|
|
679
682
|
const obj = {
|
|
680
|
-
description: requestBodyDetails.description,
|
|
681
683
|
required: requestBodyDetails.required || false,
|
|
682
684
|
};
|
|
683
685
|
|
|
686
|
+
if (requestBodyDetails.description) {
|
|
687
|
+
obj.description = requestBodyDetails.description;
|
|
688
|
+
}
|
|
689
|
+
|
|
684
690
|
obj.content = await this.createMediaTypeObject(
|
|
685
691
|
requestBodyDetails.models
|
|
686
692
|
).catch((err) => {
|
|
@@ -692,7 +698,6 @@ class DefinitionGenerator {
|
|
|
692
698
|
|
|
693
699
|
async createMediaTypeObject(models, type) {
|
|
694
700
|
const mediaTypeObj = {};
|
|
695
|
-
|
|
696
701
|
for (const mediaTypeDocumentation of this.schemaHandler.models) {
|
|
697
702
|
if (models === undefined || models === null) {
|
|
698
703
|
throw new Error(
|
|
@@ -700,48 +705,53 @@ class DefinitionGenerator {
|
|
|
700
705
|
);
|
|
701
706
|
}
|
|
702
707
|
|
|
703
|
-
|
|
704
|
-
let contentKey
|
|
705
|
-
|
|
706
|
-
|
|
708
|
+
for (const modelContentType in models) {
|
|
709
|
+
let contentKey
|
|
710
|
+
|
|
711
|
+
if (models[modelContentType] === mediaTypeDocumentation.name) {
|
|
712
|
+
contentKey = modelContentType;
|
|
707
713
|
}
|
|
708
|
-
const obj = {};
|
|
709
714
|
|
|
710
|
-
|
|
711
|
-
if (mediaTypeDocumentation?.content) {
|
|
712
|
-
if (mediaTypeDocumentation.content[contentKey]?.example)
|
|
713
|
-
obj.example = mediaTypeDocumentation.content[contentKey].example;
|
|
715
|
+
if (contentKey) {
|
|
714
716
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
)
|
|
717
|
+
const obj = {};
|
|
718
|
+
let schema;
|
|
719
|
+
if (mediaTypeDocumentation.content) {
|
|
720
|
+
if (mediaTypeDocumentation.content[contentKey]?.example) {
|
|
721
|
+
obj.example = mediaTypeDocumentation.content[contentKey]?.example;
|
|
722
|
+
}
|
|
719
723
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
if (mediaTypeDocumentation?.example)
|
|
726
|
-
obj.example = mediaTypeDocumentation.example;
|
|
724
|
+
if (mediaTypeDocumentation.content[contentKey]?.examples) {
|
|
725
|
+
obj.examples = this.createExamples(
|
|
726
|
+
mediaTypeDocumentation.content[contentKey].examples
|
|
727
|
+
);
|
|
728
|
+
}
|
|
727
729
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
+
schema = (mediaTypeDocumentation.schema) ? mediaTypeDocumentation.schema : mediaTypeDocumentation.schemas[contentKey];
|
|
731
|
+
} else if (mediaTypeDocumentation?.contentType && mediaTypeDocumentation.schema) {
|
|
732
|
+
if (mediaTypeDocumentation.example) {
|
|
733
|
+
obj.example = mediaTypeDocumentation.example;
|
|
734
|
+
}
|
|
730
735
|
|
|
731
|
-
|
|
732
|
-
|
|
736
|
+
if (mediaTypeDocumentation.examples) {
|
|
737
|
+
obj.example = mediaTypeDocumentation.examples;
|
|
738
|
+
}
|
|
733
739
|
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
.catch((err) => {
|
|
737
|
-
throw err;
|
|
738
|
-
});
|
|
740
|
+
schema = mediaTypeDocumentation.schema;
|
|
741
|
+
}
|
|
739
742
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
+
const schemaRef = await this.schemaHandler
|
|
744
|
+
.createSchema(mediaTypeDocumentation.name)
|
|
745
|
+
.catch((err) => {
|
|
746
|
+
throw err;
|
|
747
|
+
});
|
|
743
748
|
|
|
744
|
-
|
|
749
|
+
obj.schema = {
|
|
750
|
+
$ref: schemaRef,
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
Object.assign(mediaTypeObj, { [contentKey]: obj });
|
|
754
|
+
}
|
|
745
755
|
}
|
|
746
756
|
}
|
|
747
757
|
|
|
@@ -861,7 +871,7 @@ class DefinitionGenerator {
|
|
|
861
871
|
if (
|
|
862
872
|
this.openAPI.components[type][name] &&
|
|
863
873
|
isEqual(schemaObj[name], this.openAPI.components[type][name]) ===
|
|
864
|
-
|
|
874
|
+
false
|
|
865
875
|
) {
|
|
866
876
|
delete schemaObj[name];
|
|
867
877
|
newName = `${name}-${uuid()}`;
|
package/src/schemaHandler.js
CHANGED
|
@@ -16,6 +16,12 @@ class SchemaHandler {
|
|
|
16
16
|
this.documentation = serverless.service.custom.documentation;
|
|
17
17
|
this.openAPI = openAPI;
|
|
18
18
|
|
|
19
|
+
this.shouldConvert = true;
|
|
20
|
+
if (/(3\.1\.\d)/g.test(this.openAPI.openapi)) this.shouldConvert = false;
|
|
21
|
+
|
|
22
|
+
this.logger.verbose(`OpenAPI version: ${this.openAPI.openapi}`);
|
|
23
|
+
this.logger.verbose(`Convert Schemas: ${this.shouldConvert}`);
|
|
24
|
+
|
|
19
25
|
this.modelReferences = {};
|
|
20
26
|
|
|
21
27
|
this.__standardiseModels();
|
|
@@ -42,9 +48,21 @@ class SchemaHandler {
|
|
|
42
48
|
return model;
|
|
43
49
|
}
|
|
44
50
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
if (Object.keys(model.content).length === 1) {
|
|
52
|
+
const contentType = Object.keys(model.content)[0];
|
|
53
|
+
model.contentType = contentType;
|
|
54
|
+
model.contentTypes = [contentType];
|
|
55
|
+
model.schema = model.content[contentType].schema;
|
|
56
|
+
} else {
|
|
57
|
+
model.contentType = null;
|
|
58
|
+
model.contentTypes = Object.keys(model.content);
|
|
59
|
+
model.schema = null;
|
|
60
|
+
model.schemas = {};
|
|
61
|
+
for (const key in model.content) {
|
|
62
|
+
Object.assign(model.schemas, { [key]: { schema: model.content[key].schema } });
|
|
63
|
+
}
|
|
64
|
+
// model.schema = model.content[contentType].schema;
|
|
65
|
+
}
|
|
48
66
|
|
|
49
67
|
return model;
|
|
50
68
|
};
|
|
@@ -69,43 +87,52 @@ class SchemaHandler {
|
|
|
69
87
|
async addModelsToOpenAPI() {
|
|
70
88
|
for (const model of this.models) {
|
|
71
89
|
const modelName = model.name;
|
|
72
|
-
const
|
|
90
|
+
const schemas = []
|
|
91
|
+
if (model.schema) {
|
|
92
|
+
// const modelSchema = model.schema;
|
|
93
|
+
schemas.push(model.schema)
|
|
94
|
+
} else {
|
|
95
|
+
for (const key in model.schemas) {
|
|
96
|
+
schemas.push(model.schemas[key].schema);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
73
99
|
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
100
|
+
for (const modelSchema of schemas) {
|
|
101
|
+
const convertedSchemas = await this.__dereferenceAndConvert(
|
|
102
|
+
modelSchema,
|
|
103
|
+
modelName,
|
|
104
|
+
model
|
|
105
|
+
).catch((err) => {
|
|
106
|
+
if (err instanceof Error) throw err;
|
|
107
|
+
else return err;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
if (
|
|
111
|
+
typeof convertedSchemas.schemas === "object" &&
|
|
112
|
+
!Array.isArray(convertedSchemas.schemas) &&
|
|
113
|
+
convertedSchemas.schemas !== null
|
|
114
|
+
) {
|
|
115
|
+
for (const [schemaName, schemaValue] of Object.entries(
|
|
116
|
+
convertedSchemas.schemas
|
|
117
|
+
)) {
|
|
118
|
+
if (schemaName === modelName) {
|
|
119
|
+
this.modelReferences[
|
|
120
|
+
schemaName
|
|
121
|
+
] = `#/components/schemas/${modelName}`;
|
|
122
|
+
}
|
|
82
123
|
|
|
83
|
-
|
|
84
|
-
typeof convertedSchemas.schemas === "object" &&
|
|
85
|
-
!Array.isArray(convertedSchemas.schemas) &&
|
|
86
|
-
convertedSchemas.schemas !== null
|
|
87
|
-
) {
|
|
88
|
-
for (const [schemaName, schemaValue] of Object.entries(
|
|
89
|
-
convertedSchemas.schemas
|
|
90
|
-
)) {
|
|
91
|
-
if (schemaName === modelName) {
|
|
92
|
-
this.modelReferences[
|
|
93
|
-
schemaName
|
|
94
|
-
] = `#/components/schemas/${modelName}`;
|
|
124
|
+
this.__addToComponents("schemas", schemaValue, schemaName);
|
|
95
125
|
}
|
|
96
|
-
|
|
97
|
-
|
|
126
|
+
} else {
|
|
127
|
+
throw new Error(
|
|
128
|
+
`There was an error converting the ${model.name
|
|
129
|
+
} schema. Model received looks like: \n\n${JSON.stringify(
|
|
130
|
+
model
|
|
131
|
+
)}. The convereted schema looks like \n\n${JSON.stringify(
|
|
132
|
+
convertedSchemas
|
|
133
|
+
)}`
|
|
134
|
+
);
|
|
98
135
|
}
|
|
99
|
-
} else {
|
|
100
|
-
throw new Error(
|
|
101
|
-
`There was an error converting the ${
|
|
102
|
-
model.name
|
|
103
|
-
} schema. Model received looks like: \n\n${JSON.stringify(
|
|
104
|
-
model
|
|
105
|
-
)}. The convereted schema looks like \n\n${JSON.stringify(
|
|
106
|
-
convertedSchemas
|
|
107
|
-
)}`
|
|
108
|
-
);
|
|
109
136
|
}
|
|
110
137
|
}
|
|
111
138
|
}
|
|
@@ -157,18 +184,30 @@ class SchemaHandler {
|
|
|
157
184
|
}
|
|
158
185
|
);
|
|
159
186
|
|
|
160
|
-
this.
|
|
161
|
-
|
|
162
|
-
|
|
187
|
+
if (this.shouldConvert) {
|
|
188
|
+
this.logger.verbose(
|
|
189
|
+
`dereferenced model: ${JSON.stringify(dereferencedSchema)}`
|
|
190
|
+
);
|
|
163
191
|
|
|
164
|
-
|
|
165
|
-
|
|
192
|
+
this.logger.verbose(`converting model: ${name}`);
|
|
193
|
+
const convertedSchemas = SchemaConvertor.convert(
|
|
194
|
+
dereferencedSchema,
|
|
195
|
+
name
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
this.logger.verbose(
|
|
199
|
+
`converted schemas: ${JSON.stringify(convertedSchemas)}`
|
|
200
|
+
);
|
|
201
|
+
return convertedSchemas;
|
|
202
|
+
}
|
|
166
203
|
|
|
167
204
|
this.logger.verbose(
|
|
168
|
-
`
|
|
205
|
+
`dereferenced model: ${JSON.stringify({
|
|
206
|
+
schemas: { [name]: dereferencedSchema },
|
|
207
|
+
})}`
|
|
169
208
|
);
|
|
170
209
|
|
|
171
|
-
return
|
|
210
|
+
return { schemas: { [name]: dereferencedSchema } };
|
|
172
211
|
}
|
|
173
212
|
|
|
174
213
|
async __dereferenceSchema(schema) {
|
|
@@ -270,10 +309,8 @@ class SchemaHandler {
|
|
|
270
309
|
__HTTPError(error, model) {
|
|
271
310
|
if (error.message.includes("HTTP ERROR")) {
|
|
272
311
|
throw new Error(
|
|
273
|
-
`There was an error dereferencing ${
|
|
274
|
-
|
|
275
|
-
} schema. \n\n dereferencing message: ${
|
|
276
|
-
error.message
|
|
312
|
+
`There was an error dereferencing ${model.name
|
|
313
|
+
} schema. \n\n dereferencing message: ${error.message
|
|
277
314
|
} \n\n Model received: ${JSON.stringify(model)}`
|
|
278
315
|
);
|
|
279
316
|
}
|
package/test.js
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
const $RefParser = require("@apidevtools/json-schema-ref-parser");
|
|
2
|
+
|
|
3
|
+
const schema = {
|
|
4
|
+
$id: "http://schemas.aat.org.uk/build/ProgrammeRegistration.json",
|
|
5
|
+
$schema: "http://json-schema.org/draft-04/schema#",
|
|
6
|
+
title: "ProgrammeRegistration",
|
|
7
|
+
description: "Programme registration schema",
|
|
8
|
+
required: ["programmeRegistrationDetail"],
|
|
9
|
+
additionalProperties: false,
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
programmeRegistrationDetail: {
|
|
13
|
+
$ref: "#/definitions/ProgrammeRegistrationType",
|
|
14
|
+
},
|
|
15
|
+
programmeRegistrationQuestionResponse: {
|
|
16
|
+
anyOf: [
|
|
17
|
+
{ type: "null" },
|
|
18
|
+
{
|
|
19
|
+
type: "object",
|
|
20
|
+
additionalProperties: false,
|
|
21
|
+
properties: {
|
|
22
|
+
questions: {
|
|
23
|
+
type: "array",
|
|
24
|
+
items: { $ref: "#/definitions/QuestionResponse" },
|
|
25
|
+
minItems: 1,
|
|
26
|
+
maxItems: 30,
|
|
27
|
+
uniqueItems: true,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
autoOrderCreate: {
|
|
34
|
+
anyOf: [{ type: "boolean", default: false }, { type: "null" }],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
version: "1.1.1",
|
|
38
|
+
definitions: {
|
|
39
|
+
ProgrammeRegistrationType: {
|
|
40
|
+
title: "ProgrammeRegistrationType",
|
|
41
|
+
description: "programme registration type",
|
|
42
|
+
type: "object",
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
required: [
|
|
45
|
+
"programmeRegistrationId",
|
|
46
|
+
"contactId",
|
|
47
|
+
"trainingProviderOrganisationId",
|
|
48
|
+
"qualificationId",
|
|
49
|
+
"startingLevel",
|
|
50
|
+
],
|
|
51
|
+
properties: {
|
|
52
|
+
programmeRegistrationId: { $ref: "#/definitions/UUID" },
|
|
53
|
+
programmeRegistrationCRMId: { $ref: "#/definitions/UUID" },
|
|
54
|
+
contactId: { $ref: "#/definitions/UUID" },
|
|
55
|
+
trainingProviderOrganisationId: { $ref: "#/definitions/UUID" },
|
|
56
|
+
qualificationId: { $ref: "#/definitions/UUID" },
|
|
57
|
+
qualificationLocalCode: {
|
|
58
|
+
anyOf: [{ type: "null" }, { type: "string" }],
|
|
59
|
+
},
|
|
60
|
+
startingLevel: { $ref: "#/definitions/UUID" },
|
|
61
|
+
expectedEndLevel: {
|
|
62
|
+
anyOf: [{ $ref: "#/definitions/UUID" }, { type: "null" }],
|
|
63
|
+
},
|
|
64
|
+
currentLevel: {
|
|
65
|
+
anyOf: [{ $ref: "#/definitions/UUID" }, { type: "null" }],
|
|
66
|
+
},
|
|
67
|
+
registrationDate: {
|
|
68
|
+
anyOf: [{ $ref: "#/definitions/AATDate" }, { type: "null" }],
|
|
69
|
+
},
|
|
70
|
+
fundingType: {
|
|
71
|
+
anyOf: [
|
|
72
|
+
{ type: "null" },
|
|
73
|
+
{ $ref: "#/definitions/ProgrammeRegistrationFundingType" },
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
endDate: {
|
|
77
|
+
anyOf: [{ type: "null" }, { $ref: "#/definitions/AATDate" }],
|
|
78
|
+
},
|
|
79
|
+
fundingTypeMembershipFees: {
|
|
80
|
+
anyOf: [
|
|
81
|
+
{ type: "null" },
|
|
82
|
+
{ $ref: "#/definitions/ProgrammeRegistrationFundingType" },
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
apprenticeship: { type: "boolean", default: false },
|
|
86
|
+
apprenticeshipStartDate: {
|
|
87
|
+
anyOf: [{ $ref: "#/definitions/AATDate" }, { type: "null" }],
|
|
88
|
+
},
|
|
89
|
+
fullTime: { type: "boolean", default: false },
|
|
90
|
+
distanceLearning: { type: "boolean", default: false },
|
|
91
|
+
payingOrganisationId: {
|
|
92
|
+
anyOf: [{ $ref: "#/definitions/UUID" }, { type: "null" }],
|
|
93
|
+
},
|
|
94
|
+
employmentId: {
|
|
95
|
+
anyOf: [{ $ref: "#/definitions/UUID" }, { type: "null" }],
|
|
96
|
+
},
|
|
97
|
+
poNumber: {
|
|
98
|
+
anyOf: [{ type: "string", maxLength: 50 }, { type: "null" }],
|
|
99
|
+
},
|
|
100
|
+
poRequester: {
|
|
101
|
+
anyOf: [{ type: "string", maxLength: 50 }, { type: "null" }],
|
|
102
|
+
},
|
|
103
|
+
assessmentPoNumber: {
|
|
104
|
+
anyOf: [{ type: "string", maxLength: 50 }, { type: "null" }],
|
|
105
|
+
},
|
|
106
|
+
smartEPAId: {
|
|
107
|
+
anyOf: [{ $ref: "#/definitions/UUID" }, { type: "null" }],
|
|
108
|
+
},
|
|
109
|
+
autoOrderCreate: {
|
|
110
|
+
anyOf: [{ type: "boolean", default: false }, { type: "null" }],
|
|
111
|
+
},
|
|
112
|
+
membershipApplicationId: {
|
|
113
|
+
anyOf: [{ $ref: "#/definitions/UUID" }, { type: "null" }],
|
|
114
|
+
},
|
|
115
|
+
gatewayDate: {
|
|
116
|
+
anyOf: [{ $ref: "#/definitions/AATDate" }, { type: "null" }],
|
|
117
|
+
},
|
|
118
|
+
registrationStatus: {
|
|
119
|
+
anyOf: [{ type: "null" }, { type: "string" }],
|
|
120
|
+
},
|
|
121
|
+
registrationStatusDate: {
|
|
122
|
+
anyOf: [{ $ref: "#/definitions/AATDate" }, { type: "null" }],
|
|
123
|
+
},
|
|
124
|
+
givenName: { anyOf: [{ type: "null" }, { type: "string" }] },
|
|
125
|
+
familyName: { anyOf: [{ type: "null" }, { type: "string" }] },
|
|
126
|
+
memberId: { anyOf: [{ type: "null" }, { type: "string" }] },
|
|
127
|
+
birthDate: {
|
|
128
|
+
anyOf: [{ $ref: "#/definitions/AATDate" }, { type: "null" }],
|
|
129
|
+
},
|
|
130
|
+
epaRegisteredOn: {
|
|
131
|
+
anyOf: [
|
|
132
|
+
{ type: "null" },
|
|
133
|
+
{
|
|
134
|
+
type: "boolean",
|
|
135
|
+
description:
|
|
136
|
+
"Indicates the user is studying the associated apprenticeship",
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
QuestionResponse: {
|
|
143
|
+
title: "QuestionResponse",
|
|
144
|
+
description: "response to a question",
|
|
145
|
+
type: "object",
|
|
146
|
+
additionalProperties: false,
|
|
147
|
+
required: ["questionId", "responseId", "response"],
|
|
148
|
+
properties: {
|
|
149
|
+
responseId: { $ref: "#/definitions/UUID" },
|
|
150
|
+
questionId: { $ref: "#/definitions/UUID" },
|
|
151
|
+
response: {
|
|
152
|
+
type: "object",
|
|
153
|
+
anyOf: [
|
|
154
|
+
{ text: { type: "string" } },
|
|
155
|
+
{ multiLineText: { type: "string" } },
|
|
156
|
+
{ currency: { type: "number" } },
|
|
157
|
+
{ date: { $ref: "#/source/base/AATDate.json" } },
|
|
158
|
+
{ decimal: { type: "number" } },
|
|
159
|
+
{ optionSet: { type: "string" } },
|
|
160
|
+
{ wholeNumber: { type: "integer" } },
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
UUID: {
|
|
166
|
+
title: "UUID",
|
|
167
|
+
description: "Universally Unique Identifier (all lowercase)",
|
|
168
|
+
type: "string",
|
|
169
|
+
pattern: "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}",
|
|
170
|
+
},
|
|
171
|
+
AATDate: {
|
|
172
|
+
title: "AATDate",
|
|
173
|
+
description: "AAT Date formatted",
|
|
174
|
+
type: "string",
|
|
175
|
+
examples: ["2014-07-17T10:02:21Z"],
|
|
176
|
+
},
|
|
177
|
+
ProgrammeRegistrationFundingType: {
|
|
178
|
+
title: "ProgrammeRegistrationFundingType",
|
|
179
|
+
description: "funding types for programme registrations",
|
|
180
|
+
type: "string",
|
|
181
|
+
enum: [
|
|
182
|
+
"Employer",
|
|
183
|
+
"Student",
|
|
184
|
+
"Training Provider",
|
|
185
|
+
"AAT(SA)",
|
|
186
|
+
"AAT NZICA",
|
|
187
|
+
"Unknown",
|
|
188
|
+
"Government",
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const main = async () => {
|
|
195
|
+
let deReferencedSchema = await $RefParser
|
|
196
|
+
.dereference("schemas.aat.org.uk/build/ProgrammeRegistration.json")
|
|
197
|
+
.catch((err) => {
|
|
198
|
+
throw err;
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
console.log(deReferencedSchema);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
main().catch((err) => console.error(err));
|
package/test2.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
const $RefParser = require("@apidevtools/json-schema-ref-parser");
|
|
2
|
+
|
|
3
|
+
const schema = {
|
|
4
|
+
$id: "http://schemas.aat.org.uk/build/TrainingProviderApprovalDetail.json",
|
|
5
|
+
$schema: "http://json-schema.org/draft-04/schema#",
|
|
6
|
+
title: "TrainingProviderApprovalDetail",
|
|
7
|
+
description: "Training Provider Approval",
|
|
8
|
+
required: ["approval"],
|
|
9
|
+
additionalProperties: false,
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
abc: { type: "string" },
|
|
13
|
+
// approval: { $ref: "#/definitions/TrainingProviderApproval" },
|
|
14
|
+
// approvalQuestionResponse: {
|
|
15
|
+
// anyOf: [
|
|
16
|
+
// {
|
|
17
|
+
// type: "object",
|
|
18
|
+
// properties: {
|
|
19
|
+
// questions: {
|
|
20
|
+
// type: "array",
|
|
21
|
+
// items: { $ref: "#/definitions/QuestionResponse" },
|
|
22
|
+
// minItems: 1,
|
|
23
|
+
// maxItems: 30,
|
|
24
|
+
// uniqueItems: true,
|
|
25
|
+
// },
|
|
26
|
+
// },
|
|
27
|
+
// },
|
|
28
|
+
// { type: "null" },
|
|
29
|
+
// ],
|
|
30
|
+
// },
|
|
31
|
+
},
|
|
32
|
+
version: "1.1.1",
|
|
33
|
+
definitions: {
|
|
34
|
+
// TrainingProviderApproval: {
|
|
35
|
+
// title: "TrainingProviderApproval",
|
|
36
|
+
// description: "Training Provider Approval",
|
|
37
|
+
// required: [
|
|
38
|
+
// "TPapprovalId",
|
|
39
|
+
// "approvalCRMId",
|
|
40
|
+
// "qualificationId",
|
|
41
|
+
// "status",
|
|
42
|
+
// "qualificationName",
|
|
43
|
+
// "organisationId",
|
|
44
|
+
// ],
|
|
45
|
+
// additionalProperties: false,
|
|
46
|
+
// type: "object",
|
|
47
|
+
// properties: {
|
|
48
|
+
// TPapprovalId: { $ref: "#/definitions/UUID" },
|
|
49
|
+
// TPapprovalCRMId: {
|
|
50
|
+
// anyOf: [{ $ref: "#/definitions/UUID" }, { type: "null" }],
|
|
51
|
+
// },
|
|
52
|
+
// approvalCRMId: { $ref: "#/definitions/UUID" },
|
|
53
|
+
// organisationId: { $ref: "#/definitions/UUID" },
|
|
54
|
+
// qualificationName: { type: "string", maxLength: 100 },
|
|
55
|
+
// qualificationShortName: {
|
|
56
|
+
// anyOf: [{ type: "string", maxLength: 100 }, { type: "null" }],
|
|
57
|
+
// },
|
|
58
|
+
// localCode: {
|
|
59
|
+
// anyOf: [{ type: "string", maxLength: 20 }, { type: "null" }],
|
|
60
|
+
// },
|
|
61
|
+
// aatId: { anyOf: [{ type: "number" }, { type: "null" }] },
|
|
62
|
+
// qualificationId: { $ref: "#/definitions/UUID" },
|
|
63
|
+
// status: {
|
|
64
|
+
// type: "string",
|
|
65
|
+
// enum: [
|
|
66
|
+
// "Sales Prospect",
|
|
67
|
+
// "EOI Sent",
|
|
68
|
+
// "EOI Received",
|
|
69
|
+
// "EOI More Information Requested",
|
|
70
|
+
// "EOI Declined",
|
|
71
|
+
// "EOI Closed",
|
|
72
|
+
// "Application On Hold By TP",
|
|
73
|
+
// "Application Pack Sent",
|
|
74
|
+
// "Application Pending",
|
|
75
|
+
// "Approval Visit Scheduled",
|
|
76
|
+
// "Approval Visit Action Plan",
|
|
77
|
+
// "Application Closed",
|
|
78
|
+
// "Application Withdrawn",
|
|
79
|
+
// "Approved",
|
|
80
|
+
// "Conditionally Approved",
|
|
81
|
+
// "Referred to Conduct & Compliance",
|
|
82
|
+
// "Rejected",
|
|
83
|
+
// "Inactive",
|
|
84
|
+
// "Withdrawn",
|
|
85
|
+
// ],
|
|
86
|
+
// },
|
|
87
|
+
// statusDate: {
|
|
88
|
+
// anyOf: [{ $ref: "#/definitions/AATDate" }, { type: "null" }],
|
|
89
|
+
// },
|
|
90
|
+
// fromDate: {
|
|
91
|
+
// anyOf: [{ $ref: "#/definitions/AATDate" }, { type: "null" }],
|
|
92
|
+
// },
|
|
93
|
+
// untilDate: {
|
|
94
|
+
// anyOf: [{ $ref: "#/definitions/AATDate" }, { type: "null" }],
|
|
95
|
+
// },
|
|
96
|
+
// },
|
|
97
|
+
// },
|
|
98
|
+
QuestionResponse: {
|
|
99
|
+
title: "QuestionResponse",
|
|
100
|
+
description: "response to a question",
|
|
101
|
+
type: "object",
|
|
102
|
+
additionalProperties: false,
|
|
103
|
+
required: ["questionId", "responseId", "response"],
|
|
104
|
+
properties: {
|
|
105
|
+
responseId: { $ref: "#/definitions/UUID" },
|
|
106
|
+
questionId: { $ref: "#/definitions/UUID" },
|
|
107
|
+
response: {
|
|
108
|
+
type: "object",
|
|
109
|
+
anyOf: [
|
|
110
|
+
{ text: { type: "string" } },
|
|
111
|
+
{ multiLineText: { type: "string" } },
|
|
112
|
+
{ currency: { type: "number" } },
|
|
113
|
+
{ date: { $ref: "#/source/base/AATDate.json" } },
|
|
114
|
+
{ decimal: { type: "number" } },
|
|
115
|
+
{ optionSet: { type: "string" } },
|
|
116
|
+
{ wholeNumber: { type: "integer" } },
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
UUID: {
|
|
122
|
+
title: "UUID",
|
|
123
|
+
description: "Universally Unique Identifier (all lowercase)",
|
|
124
|
+
type: "string",
|
|
125
|
+
pattern: "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}",
|
|
126
|
+
},
|
|
127
|
+
AATDate: {
|
|
128
|
+
title: "AATDate",
|
|
129
|
+
description: "AAT Date formatted",
|
|
130
|
+
type: "string",
|
|
131
|
+
examples: ["2014-07-17T10:02:21Z"],
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const schema2 = { type: "object", properties: { a: { type: "string" } } };
|
|
137
|
+
|
|
138
|
+
const main = async () => {
|
|
139
|
+
const bundledSchema = await $RefParser.bundle(schema).catch((err) => {
|
|
140
|
+
throw err;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
console.log(bundledSchema);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
main().catch((err) => console.error(err));
|