UNPKG

2.9 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const javaUtil_1 = require("./java/javaUtil");
4const UPDATE = javaUtil_1.newHashSet('PUT', 'PATCH');
5class CodegenOperation {
6 constructor() {
7 this.responseHeaders = [];
8 this.hasMore = true;
9 this.isResponseBinary = false;
10 this.hasReference = false;
11 this.allParams = [];
12 this.bodyParams = [];
13 this.pathParams = [];
14 this.queryParams = [];
15 this.headerParams = [];
16 this.formParams = [];
17 this.responses = [];
18 this.imports = javaUtil_1.newHashSet();
19 }
20 /**
21 * Check if act as Restful index method
22 *
23 * @return true if act as Restful index method, false otherwise
24 */
25 isRestfulIndex() {
26 return 'GET' === this.httpMethod && '' === this.pathWithoutBaseName();
27 }
28 /**
29 * Check if act as Restful show method
30 *
31 * @return true if act as Restful show method, false otherwise
32 */
33 isRestfulShow() {
34 return 'GET' === this.httpMethod && this.isMemberPath();
35 }
36 /**
37 * Check if act as Restful create method
38 *
39 * @return true if act as Restful create method, false otherwise
40 */
41 isRestfulCreate() {
42 return 'POST' === this.httpMethod && '' === this.pathWithoutBaseName();
43 }
44 /**
45 * Check if act as Restful update method
46 *
47 * @return true if act as Restful update method, false otherwise
48 */
49 isRestfulUpdate() {
50 return UPDATE.contains(this.httpMethod) && this.isMemberPath();
51 }
52 /**
53 * Check if act as Restful destroy method
54 *
55 * @return true if act as Restful destroy method, false otherwise
56 */
57 isRestfulDestroy() {
58 return 'DELETE' === this.httpMethod && this.isMemberPath();
59 }
60 /**
61 * Check if Restful-style
62 *
63 * @return true if Restful-style, false otherwise
64 */
65 isRestful() {
66 return (this.isRestfulIndex() ||
67 this.isRestfulShow() ||
68 this.isRestfulCreate() ||
69 this.isRestfulUpdate() ||
70 this.isRestfulDestroy());
71 }
72 /**
73 * Get the substring except baseName from path
74 *
75 * @return the substring
76 */
77 pathWithoutBaseName() {
78 return this.baseName != null
79 ? this.path.split('/' + this.baseName.toLowerCase()).join('')
80 : this.path;
81 }
82 /**
83 * Check if the path match format /xxx/:id
84 *
85 * @return true if path act as member
86 */
87 isMemberPath() {
88 if (this.pathParams.length !== 1) {
89 return false;
90 }
91 const id = this.pathParams[0].baseName;
92 return '/{' + id + '}' === this.pathWithoutBaseName();
93 }
94 toString() {
95 return `${this.baseName}(${this.path})`;
96 }
97}
98exports.default = CodegenOperation;
99//# sourceMappingURL=CodegenOperation.js.map
\No newline at end of file