forked from acacode/swagger-typescript-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodelTypes.js
37 lines (30 loc) · 1.13 KB
/
modelTypes.js
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
const _ = require('lodash');
const { formatters } = require("./typeFormatters");
const { checkAndRenameModelName } = require("./modelNames");
const { formatDescription } = require("./common")
const { getTypeData } = require('./components');
const CONTENT_KEYWORD = '__CONTENT__';
const contentWrapersByTypeIdentifier = {
'enum': `{\r\n${CONTENT_KEYWORD} \r\n }`,
'interface': `{\r\n${CONTENT_KEYWORD}}`,
'type': `= ${CONTENT_KEYWORD}`,
}
const getModelType = typeInfo => {
const { typeIdentifier, name: originalName, content, type, description } = getTypeData(typeInfo);
if (!contentWrapersByTypeIdentifier[typeIdentifier]) {
throw new Error(`${typeIdentifier} - type identifier is unknown for this utility`)
}
const resultContent = formatters[type] ? formatters[type](content) : content;
const name = checkAndRenameModelName(originalName);
return {
typeIdentifier,
name,
rawContent: resultContent,
description: formatDescription(description),
content: _.replace(contentWrapersByTypeIdentifier[typeIdentifier], CONTENT_KEYWORD, resultContent)
}
}
module.exports = {
getModelType,
checkAndRenameModelName,
}