-
-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathschemaAnalyzer.ts
More file actions
78 lines (72 loc) · 1.64 KB
/
Copy pathschemaAnalyzer.ts
File metadata and controls
78 lines (72 loc) · 1.64 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import type { Field, Resource } from '@api-platform/api-doc-parser';
import {
getFiltersParametersFromSchema,
getOrderParametersFromSchema,
} from '../introspection/schemaAnalyzer.js';
import type { SchemaAnalyzer } from '../types.js';
/**
* @param schema The schema of a resource
*
* @returns The name of the reference field
*/
const getFieldNameFromSchema = (schema: Resource) => {
if (!schema.fields?.[0]) {
return '';
}
if (schema.fields.find((schemaField) => schemaField.name === 'id')) {
return 'id';
}
return schema.fields[0].name;
};
/**
* @returns The type of the field
*/
const getFieldType = (field: Field) => {
switch (field.type) {
case 'array':
return 'array';
case 'string':
case 'byte':
case 'binary':
case 'hexBinary':
case 'base64Binary':
case 'uuid':
case 'password':
return 'text';
case 'integer':
case 'negativeInteger':
case 'nonNegativeInteger':
case 'positiveInteger':
case 'nonPositiveInteger':
return 'integer';
case 'number':
case 'decimal':
case 'double':
case 'float':
return 'float';
case 'boolean':
return 'boolean';
case 'date':
return 'date';
case 'dateTime':
case 'duration':
case 'time':
return 'dateTime';
case 'email':
return 'email';
case 'url':
return 'url';
default:
return 'text';
}
};
const getSubmissionErrors = () => null;
export default function schemaAnalyzer(): SchemaAnalyzer {
return {
getFieldNameFromSchema,
getOrderParametersFromSchema,
getFiltersParametersFromSchema,
getFieldType,
getSubmissionErrors,
};
}