|
1 |
| -// The Angular client template is currently NOT TESTET! |
2 |
| - |
3 |
| -<if(hasOperations)> |
4 |
| -<if(generateClientInterfaces)> |
5 |
| -export interface I<class> { |
6 |
| -<operations:{operation | |
7 |
| -<if(operation.HasDocumentation)> /** |
8 |
| -<if(operation.HasSummary)> * <operation.Summary><endif> |
9 |
| -<operation.Parameters:{parameter | |
10 |
| -<if(parameter.HasDescription)> * @<parameter.VariableNameLower> <parameter.Description><endif>}> |
11 |
| -<if(operation.HasResultDescription)> * @return <operation.ResultDescription><endif> |
12 |
| - */ |
13 |
| -<endif> <operation.OperationNameLower>(<operation.Parameters:{parameter | <parameter.VariableNameLower>: <parameter.Type><if(!parameter.IsLast)>, <endif>}>): ng.IPromise\<<operation.ResultType>>; |
14 |
| -}>} |
15 |
| -<endif> |
16 |
| - |
17 |
| -export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{ |
18 |
| - baseUrl: string = undefined; |
19 |
| - http: ng.IHttpService = null; |
20 |
| - |
21 |
| - constructor($http: ng.IHttpService, baseUrl?: string) { |
22 |
| - this.http = $http; |
23 |
| - this.baseUrl = baseUrl !== undefined ? baseUrl : "<baseUrl>"; |
24 |
| - } |
25 |
| -<operations:{operation | |
26 |
| - |
27 |
| -<if(operation.HasDocumentation)> /** |
28 |
| -<if(operation.HasSummary)> * <operation.Summary><endif> |
29 |
| -<operation.Parameters:{parameter | |
30 |
| -<if(parameter.HasDescription)> * @<parameter.VariableNameLower> <parameter.Description><endif>}> |
31 |
| -<if(operation.HasResultDescription)> * @return <operation.ResultDescription><endif> |
32 |
| - */ |
33 |
| -<endif> <operation.OperationNameLower>(<operation.Parameters:{parameter | <parameter.VariableNameLower>: <parameter.Type><if(!parameter.IsLast)>, <endif>}>): ng.IPromise\<<operation.ResultType>> { |
34 |
| - var url = this.baseUrl + "/<operation.Path>?"; |
35 |
| - |
36 |
| -<operation.PathParameters:{parameter | |
37 |
| - if (<parameter.VariableNameLower> === undefined || <parameter.VariableNameLower> === null) |
38 |
| - throw new Error("The parameter '<parameter.VariableNameLower>' must be defined."); |
39 |
| - <if(parameter.IsDate)> |
40 |
| - url = url.replace("{<parameter.Name>\}", "" + <parameter.VariableNameLower>.toJSON()); |
41 |
| - <else> |
42 |
| - url = url.replace("{<parameter.Name>\}", "" + <parameter.VariableNameLower>); |
43 |
| - <endif> |
44 |
| -}> |
45 |
| - |
46 |
| -<operation.QueryParameters:{parameter | |
47 |
| - <if(parameter.IsOptional)> |
48 |
| - if (<parameter.VariableNameLower> !== undefined && <parameter.VariableNameLower> !== null) |
49 |
| - <else> |
50 |
| - if (<parameter.VariableNameLower> === undefined || <parameter.VariableNameLower> === null) |
51 |
| - throw new Error("The parameter '<parameter.VariableNameLower>' must be defined."); |
52 |
| - else |
53 |
| - <endif> |
54 |
| - <if(parameter.IsDate)> |
55 |
| - <if(parameter.IsArray)> |
56 |
| - <parameter.VariableNameLower>.forEach(item => { url += "<parameter.Name>=" + encodeURIComponent("" + item.toJSON()) + "&"; \}); |
57 |
| - <else> |
58 |
| - url += "<parameter.Name>=" + encodeURIComponent("" + <parameter.VariableNameLower>.toJSON()) + "&"; |
59 |
| - <endif> |
60 |
| - <else> |
61 |
| - <if(parameter.IsArray)> |
62 |
| - <parameter.VariableNameLower>.forEach(item => { url += "<parameter.Name>=" + encodeURIComponent("" + item) + "&"; \}); |
63 |
| - <else> |
64 |
| - url += "<parameter.Name>=" + encodeURIComponent("" + <parameter.VariableNameLower>) + "&"; |
65 |
| - <endif> |
66 |
| - <endif> |
67 |
| -}> |
68 |
| - |
69 |
| -<if(operation.HasContent)> |
70 |
| - var content = JSON.stringify(<operation.ContentParameter.VariableNameLower>); |
71 |
| -<else> |
72 |
| - var content = ""; |
73 |
| -<endif> |
74 |
| - |
75 |
| - return this.http({ |
76 |
| - url: url, |
77 |
| - method: "<operation.HttpMethodUpper>", |
78 |
| - data: content, |
79 |
| - transformResponse: [], |
80 |
| - headers: { |
81 |
| -<operation.HeaderParameters:{parameter | |
82 |
| - "<parameter.Name>": <parameter.VariableNameLower>, |
83 |
| -}> "Content-Type": "application/json; charset=UTF-8" |
84 |
| - \} |
85 |
| - \}).then((response) => { |
86 |
| - return this.process<operation.OperationNameUpper>(response); |
87 |
| - \}); |
88 |
| - \} |
89 |
| - |
90 |
| - private process<operation.OperationNameUpper>(response: any) { |
91 |
| - var data = response.data.replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \}); |
92 |
| - var status = response.status; |
93 |
| - |
94 |
| -<operation.Responses:{response | |
95 |
| - if (status === <response.StatusCode>) { |
96 |
| -<if(response.HasType)> |
97 |
| - var result<response.StatusCode>: <response.Type> = null; |
98 |
| - <if(response.IsDate)> |
99 |
| - result<response.StatusCode> = new Date(data); |
100 |
| - <else> |
101 |
| - result<response.StatusCode> = \<<response.Type>>JSON.parse(data); |
102 |
| - <endif> |
103 |
| - <if(response.IsSuccess)> |
104 |
| - return result<response.StatusCode>; |
105 |
| - <else> |
106 |
| - throw result<response.StatusCode>; |
107 |
| - <endif> |
108 |
| -<endif> |
109 |
| - \} |
110 |
| - else}> |
111 |
| - { |
112 |
| -<if(operation.HasDefaultResponse)> |
113 |
| - var result: <operation.DefaultResponse.Type> = null; |
114 |
| - <if(operation.DefaultResponse.IsDate)> |
115 |
| - result = new Date(data); |
116 |
| - <else> |
117 |
| - result = \<<operation.DefaultResponse.Type>>JSON.parse(data); |
118 |
| - <endif> |
119 |
| - <if(operation.DefaultResponse.IsSuccess)> |
120 |
| - return result; |
121 |
| - <else> |
122 |
| - throw result; |
123 |
| - <endif> |
124 |
| -<else> |
125 |
| - throw "error_no_callback_for_the_received_http_status"; |
126 |
| -<endif> |
127 |
| - \} |
128 |
| - \} |
129 |
| -}>} |
130 |
| -<endif> |
131 |
| - |
| 1 | +// The Angular client template is currently NOT TESTET! |
| 2 | + |
| 3 | +<if(hasOperations)> |
| 4 | +<if(generateClientInterfaces)> |
| 5 | +export interface I<class> { |
| 6 | +<operations:{operation | |
| 7 | +<if(operation.HasDocumentation)> /** |
| 8 | +<if(operation.HasSummary)> * <operation.Summary><endif> |
| 9 | +<operation.Parameters:{parameter | |
| 10 | +<if(parameter.HasDescription)> * @<parameter.VariableNameLower> <parameter.Description><endif>}> |
| 11 | +<if(operation.HasResultDescription)> * @return <operation.ResultDescription><endif> |
| 12 | + */ |
| 13 | +<endif> <operation.OperationNameLower>(<operation.Parameters:{parameter | <parameter.VariableNameLower>: <parameter.Type><if(!parameter.IsLast)>, <endif>}>): ng.IPromise\<<operation.ResultType>>; |
| 14 | +}>} |
| 15 | +<endif> |
| 16 | + |
| 17 | +export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{ |
| 18 | + private baseUrl: string = undefined; |
| 19 | + private http: ng.IHttpService = null; |
| 20 | + private jsonParseReviver: (key: string, value: any) => any = undefined; |
| 21 | + |
| 22 | + constructor($http: ng.IHttpService, baseUrl?: string, jsonParseReviver?: (key: string, value: any) => any) { |
| 23 | + this.http = $http; |
| 24 | + this.baseUrl = baseUrl !== undefined ? baseUrl : "<baseUrl>"; |
| 25 | + this.jsonParseReviver = jsonParseReviver; |
| 26 | + } |
| 27 | +<operations:{operation | |
| 28 | + |
| 29 | +<if(operation.HasDocumentation)> /** |
| 30 | +<if(operation.HasSummary)> * <operation.Summary><endif> |
| 31 | +<operation.Parameters:{parameter | |
| 32 | +<if(parameter.HasDescription)> * @<parameter.VariableNameLower> <parameter.Description><endif>}> |
| 33 | +<if(operation.HasResultDescription)> * @return <operation.ResultDescription><endif> |
| 34 | + */ |
| 35 | +<endif> <operation.OperationNameLower>(<operation.Parameters:{parameter | <parameter.VariableNameLower>: <parameter.Type><if(!parameter.IsLast)>, <endif>}>): ng.IPromise\<<operation.ResultType>> { |
| 36 | + var url = this.baseUrl + "/<operation.Path>?"; |
| 37 | + |
| 38 | +<operation.PathParameters:{parameter | |
| 39 | + if (<parameter.VariableNameLower> === undefined || <parameter.VariableNameLower> === null) |
| 40 | + throw new Error("The parameter '<parameter.VariableNameLower>' must be defined."); |
| 41 | + <if(parameter.IsDate)> |
| 42 | + url = url.replace("{<parameter.Name>\}", "" + <parameter.VariableNameLower>.toJSON()); |
| 43 | + <else> |
| 44 | + url = url.replace("{<parameter.Name>\}", "" + <parameter.VariableNameLower>); |
| 45 | + <endif> |
| 46 | +}> |
| 47 | + |
| 48 | +<operation.QueryParameters:{parameter | |
| 49 | + <if(parameter.IsOptional)> |
| 50 | + if (<parameter.VariableNameLower> !== undefined && <parameter.VariableNameLower> !== null) |
| 51 | + <else> |
| 52 | + if (<parameter.VariableNameLower> === undefined || <parameter.VariableNameLower> === null) |
| 53 | + throw new Error("The parameter '<parameter.VariableNameLower>' must be defined."); |
| 54 | + else |
| 55 | + <endif> |
| 56 | + <if(parameter.IsDate)> |
| 57 | + <if(parameter.IsArray)> |
| 58 | + <parameter.VariableNameLower>.forEach(item => { url += "<parameter.Name>=" + encodeURIComponent("" + item.toJSON()) + "&"; \}); |
| 59 | + <else> |
| 60 | + url += "<parameter.Name>=" + encodeURIComponent("" + <parameter.VariableNameLower>.toJSON()) + "&"; |
| 61 | + <endif> |
| 62 | + <else> |
| 63 | + <if(parameter.IsArray)> |
| 64 | + <parameter.VariableNameLower>.forEach(item => { url += "<parameter.Name>=" + encodeURIComponent("" + item) + "&"; \}); |
| 65 | + <else> |
| 66 | + url += "<parameter.Name>=" + encodeURIComponent("" + <parameter.VariableNameLower>) + "&"; |
| 67 | + <endif> |
| 68 | + <endif> |
| 69 | +}> |
| 70 | + |
| 71 | +<if(operation.HasContent)> |
| 72 | + var content = JSON.stringify(<operation.ContentParameter.VariableNameLower>); |
| 73 | +<else> |
| 74 | + var content = ""; |
| 75 | +<endif> |
| 76 | + |
| 77 | + return this.http({ |
| 78 | + url: url, |
| 79 | + method: "<operation.HttpMethodUpper>", |
| 80 | + data: content, |
| 81 | + transformResponse: [], |
| 82 | + headers: { |
| 83 | +<operation.HeaderParameters:{parameter | |
| 84 | + "<parameter.Name>": <parameter.VariableNameLower>, |
| 85 | +}> "Content-Type": "application/json; charset=UTF-8" |
| 86 | + \} |
| 87 | + \}).then((response) => { |
| 88 | + return this.process<operation.OperationNameUpper>(response); |
| 89 | + \}); |
| 90 | + \} |
| 91 | + |
| 92 | + private process<operation.OperationNameUpper>(response: any) { |
| 93 | + var data = response.data; |
| 94 | + var status = response.status; |
| 95 | + |
| 96 | +<operation.Responses:{response | |
| 97 | + if (status === <response.StatusCode>) { |
| 98 | +<if(response.HasType)> |
| 99 | + var result<response.StatusCode>: <response.Type> = null; |
| 100 | + <if(response.IsDate)> |
| 101 | + result<response.StatusCode> = new Date(data); |
| 102 | + <else> |
| 103 | + result<response.StatusCode> = \<<response.Type>>JSON.parse(data, this.jsonParseReviver); |
| 104 | + <endif> |
| 105 | + <if(response.IsSuccess)> |
| 106 | + return result<response.StatusCode>; |
| 107 | + <else> |
| 108 | + throw result<response.StatusCode>; |
| 109 | + <endif> |
| 110 | +<endif> |
| 111 | + \} |
| 112 | + else}> |
| 113 | + { |
| 114 | +<if(operation.HasDefaultResponse)> |
| 115 | + var result: <operation.DefaultResponse.Type> = null; |
| 116 | + <if(operation.DefaultResponse.IsDate)> |
| 117 | + result = new Date(data); |
| 118 | + <else> |
| 119 | + result = \<<operation.DefaultResponse.Type>>JSON.parse(data, this.jsonParseReviver); |
| 120 | + <endif> |
| 121 | + <if(operation.DefaultResponse.IsSuccess)> |
| 122 | + return result; |
| 123 | + <else> |
| 124 | + throw result; |
| 125 | + <endif> |
| 126 | +<else> |
| 127 | + throw "error_no_callback_for_the_received_http_status"; |
| 128 | +<endif> |
| 129 | + \} |
| 130 | + \} |
| 131 | +}>} |
| 132 | +<endif> |
| 133 | + |
0 commit comments