1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const javaUtil_1 = require("./java/javaUtil");
|
4 | const UPDATE = javaUtil_1.newHashSet('PUT', 'PATCH');
|
5 | class 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 |
|
22 |
|
23 |
|
24 |
|
25 | isRestfulIndex() {
|
26 | return 'GET' === this.httpMethod && '' === this.pathWithoutBaseName();
|
27 | }
|
28 | |
29 |
|
30 |
|
31 |
|
32 |
|
33 | isRestfulShow() {
|
34 | return 'GET' === this.httpMethod && this.isMemberPath();
|
35 | }
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 | isRestfulCreate() {
|
42 | return 'POST' === this.httpMethod && '' === this.pathWithoutBaseName();
|
43 | }
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 | isRestfulUpdate() {
|
50 | return UPDATE.contains(this.httpMethod) && this.isMemberPath();
|
51 | }
|
52 | |
53 |
|
54 |
|
55 |
|
56 |
|
57 | isRestfulDestroy() {
|
58 | return 'DELETE' === this.httpMethod && this.isMemberPath();
|
59 | }
|
60 | |
61 |
|
62 |
|
63 |
|
64 |
|
65 | isRestful() {
|
66 | return (this.isRestfulIndex() ||
|
67 | this.isRestfulShow() ||
|
68 | this.isRestfulCreate() ||
|
69 | this.isRestfulUpdate() ||
|
70 | this.isRestfulDestroy());
|
71 | }
|
72 | |
73 |
|
74 |
|
75 |
|
76 |
|
77 | pathWithoutBaseName() {
|
78 | return this.baseName != null
|
79 | ? this.path.split('/' + this.baseName.toLowerCase()).join('')
|
80 | : this.path;
|
81 | }
|
82 | |
83 |
|
84 |
|
85 |
|
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 | }
|
98 | exports.default = CodegenOperation;
|
99 |
|
\ | No newline at end of file |