/
spec-model.tsx
56 lines (54 loc) · 1.26 KB
/
spec-model.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import sequelize from 'feathers-sequelize';
import Sequelize from 'sequelize';
/**
* Creates a Sequelize database model for storing a specification.
*
* @param dbConnection The Sequelize connection to create the model for.
* @returns The created Sequelize model.
*/
export function createSpecModel(dbConnection: Sequelize.Sequelize) {
return dbConnection.define(
'specifications',
{
title: {
type: Sequelize.STRING,
allowNull: false,
},
description: {
type: Sequelize.STRING,
allowNull: true,
},
path: {
type: Sequelize.STRING,
allowNull: false,
},
},
{
freezeTableName: true,
},
);
}
/**
* Creates a Feathers service to access specifications, using the given database model.
*
* @param planModel The database model representing a specification.
* @returns The created Feathers service.
*/
export function createSpecService(specModel) {
const service = sequelize({
Model: specModel,
});
service.docs = {
description: 'Swagger/OpenAPI specs',
definitions: {
specifications: {
type: 'object',
additionalProperties: true,
},
'specifications list': {
type: 'array',
},
},
};
return service;
}