-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from NSwag/master
Release v2.8
- Loading branch information
Showing
12 changed files
with
146 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
264 changes: 133 additions & 131 deletions
264
src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJS.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,131 +1,133 @@ | ||
// The Angular client template is currently NOT TESTET! | ||
|
||
<if(hasOperations)> | ||
<if(generateClientInterfaces)> | ||
export interface I<class> { | ||
<operations:{operation | | ||
<if(operation.HasDocumentation)> /** | ||
<if(operation.HasSummary)> * <operation.Summary><endif> | ||
<operation.Parameters:{parameter | | ||
<if(parameter.HasDescription)> * @<parameter.VariableNameLower> <parameter.Description><endif>}> | ||
<if(operation.HasResultDescription)> * @return <operation.ResultDescription><endif> | ||
*/ | ||
<endif> <operation.OperationNameLower>(<operation.Parameters:{parameter | <parameter.VariableNameLower>: <parameter.Type><if(!parameter.IsLast)>, <endif>}>): ng.IPromise\<<operation.ResultType>>; | ||
}>} | ||
<endif> | ||
|
||
export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{ | ||
baseUrl: string = undefined; | ||
http: ng.IHttpService = null; | ||
|
||
constructor($http: ng.IHttpService, baseUrl?: string) { | ||
this.http = $http; | ||
this.baseUrl = baseUrl !== undefined ? baseUrl : "<baseUrl>"; | ||
} | ||
<operations:{operation | | ||
|
||
<if(operation.HasDocumentation)> /** | ||
<if(operation.HasSummary)> * <operation.Summary><endif> | ||
<operation.Parameters:{parameter | | ||
<if(parameter.HasDescription)> * @<parameter.VariableNameLower> <parameter.Description><endif>}> | ||
<if(operation.HasResultDescription)> * @return <operation.ResultDescription><endif> | ||
*/ | ||
<endif> <operation.OperationNameLower>(<operation.Parameters:{parameter | <parameter.VariableNameLower>: <parameter.Type><if(!parameter.IsLast)>, <endif>}>): ng.IPromise\<<operation.ResultType>> { | ||
var url = this.baseUrl + "/<operation.Path>?"; | ||
|
||
<operation.PathParameters:{parameter | | ||
if (<parameter.VariableNameLower> === undefined || <parameter.VariableNameLower> === null) | ||
throw new Error("The parameter '<parameter.VariableNameLower>' must be defined."); | ||
<if(parameter.IsDate)> | ||
url = url.replace("{<parameter.Name>\}", "" + <parameter.VariableNameLower>.toJSON()); | ||
<else> | ||
url = url.replace("{<parameter.Name>\}", "" + <parameter.VariableNameLower>); | ||
<endif> | ||
}> | ||
|
||
<operation.QueryParameters:{parameter | | ||
<if(parameter.IsOptional)> | ||
if (<parameter.VariableNameLower> !== undefined && <parameter.VariableNameLower> !== null) | ||
<else> | ||
if (<parameter.VariableNameLower> === undefined || <parameter.VariableNameLower> === null) | ||
throw new Error("The parameter '<parameter.VariableNameLower>' must be defined."); | ||
else | ||
<endif> | ||
<if(parameter.IsDate)> | ||
<if(parameter.IsArray)> | ||
<parameter.VariableNameLower>.forEach(item => { url += "<parameter.Name>=" + encodeURIComponent("" + item.toJSON()) + "&"; \}); | ||
<else> | ||
url += "<parameter.Name>=" + encodeURIComponent("" + <parameter.VariableNameLower>.toJSON()) + "&"; | ||
<endif> | ||
<else> | ||
<if(parameter.IsArray)> | ||
<parameter.VariableNameLower>.forEach(item => { url += "<parameter.Name>=" + encodeURIComponent("" + item) + "&"; \}); | ||
<else> | ||
url += "<parameter.Name>=" + encodeURIComponent("" + <parameter.VariableNameLower>) + "&"; | ||
<endif> | ||
<endif> | ||
}> | ||
|
||
<if(operation.HasContent)> | ||
var content = JSON.stringify(<operation.ContentParameter.VariableNameLower>); | ||
<else> | ||
var content = ""; | ||
<endif> | ||
|
||
return this.http({ | ||
url: url, | ||
method: "<operation.HttpMethodUpper>", | ||
data: content, | ||
transformResponse: [], | ||
headers: { | ||
<operation.HeaderParameters:{parameter | | ||
"<parameter.Name>": <parameter.VariableNameLower>, | ||
}> "Content-Type": "application/json; charset=UTF-8" | ||
\} | ||
\}).then((response) => { | ||
return this.process<operation.OperationNameUpper>(response); | ||
\}); | ||
\} | ||
|
||
private process<operation.OperationNameUpper>(response: any) { | ||
var data = response.data.replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \}); | ||
var status = response.status; | ||
|
||
<operation.Responses:{response | | ||
if (status === <response.StatusCode>) { | ||
<if(response.HasType)> | ||
var result<response.StatusCode>: <response.Type> = null; | ||
<if(response.IsDate)> | ||
result<response.StatusCode> = new Date(data); | ||
<else> | ||
result<response.StatusCode> = \<<response.Type>>JSON.parse(data); | ||
<endif> | ||
<if(response.IsSuccess)> | ||
return result<response.StatusCode>; | ||
<else> | ||
throw result<response.StatusCode>; | ||
<endif> | ||
<endif> | ||
\} | ||
else}> | ||
{ | ||
<if(operation.HasDefaultResponse)> | ||
var result: <operation.DefaultResponse.Type> = null; | ||
<if(operation.DefaultResponse.IsDate)> | ||
result = new Date(data); | ||
<else> | ||
result = \<<operation.DefaultResponse.Type>>JSON.parse(data); | ||
<endif> | ||
<if(operation.DefaultResponse.IsSuccess)> | ||
return result; | ||
<else> | ||
throw result; | ||
<endif> | ||
<else> | ||
throw "error_no_callback_for_the_received_http_status"; | ||
<endif> | ||
\} | ||
\} | ||
}>} | ||
<endif> | ||
|
||
// The Angular client template is currently NOT TESTET! | ||
|
||
<if(hasOperations)> | ||
<if(generateClientInterfaces)> | ||
export interface I<class> { | ||
<operations:{operation | | ||
<if(operation.HasDocumentation)> /** | ||
<if(operation.HasSummary)> * <operation.Summary><endif> | ||
<operation.Parameters:{parameter | | ||
<if(parameter.HasDescription)> * @<parameter.VariableNameLower> <parameter.Description><endif>}> | ||
<if(operation.HasResultDescription)> * @return <operation.ResultDescription><endif> | ||
*/ | ||
<endif> <operation.OperationNameLower>(<operation.Parameters:{parameter | <parameter.VariableNameLower>: <parameter.Type><if(!parameter.IsLast)>, <endif>}>): ng.IPromise\<<operation.ResultType>>; | ||
}>} | ||
<endif> | ||
|
||
export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{ | ||
private baseUrl: string = undefined; | ||
private http: ng.IHttpService = null; | ||
private jsonParseReviver: (key: string, value: any) => any = undefined; | ||
|
||
constructor($http: ng.IHttpService, baseUrl?: string, jsonParseReviver?: (key: string, value: any) => any) { | ||
this.http = $http; | ||
this.baseUrl = baseUrl !== undefined ? baseUrl : "<baseUrl>"; | ||
this.jsonParseReviver = jsonParseReviver; | ||
} | ||
<operations:{operation | | ||
|
||
<if(operation.HasDocumentation)> /** | ||
<if(operation.HasSummary)> * <operation.Summary><endif> | ||
<operation.Parameters:{parameter | | ||
<if(parameter.HasDescription)> * @<parameter.VariableNameLower> <parameter.Description><endif>}> | ||
<if(operation.HasResultDescription)> * @return <operation.ResultDescription><endif> | ||
*/ | ||
<endif> <operation.OperationNameLower>(<operation.Parameters:{parameter | <parameter.VariableNameLower>: <parameter.Type><if(!parameter.IsLast)>, <endif>}>): ng.IPromise\<<operation.ResultType>> { | ||
var url = this.baseUrl + "/<operation.Path>?"; | ||
|
||
<operation.PathParameters:{parameter | | ||
if (<parameter.VariableNameLower> === undefined || <parameter.VariableNameLower> === null) | ||
throw new Error("The parameter '<parameter.VariableNameLower>' must be defined."); | ||
<if(parameter.IsDate)> | ||
url = url.replace("{<parameter.Name>\}", "" + <parameter.VariableNameLower>.toJSON()); | ||
<else> | ||
url = url.replace("{<parameter.Name>\}", "" + <parameter.VariableNameLower>); | ||
<endif> | ||
}> | ||
|
||
<operation.QueryParameters:{parameter | | ||
<if(parameter.IsOptional)> | ||
if (<parameter.VariableNameLower> !== undefined && <parameter.VariableNameLower> !== null) | ||
<else> | ||
if (<parameter.VariableNameLower> === undefined || <parameter.VariableNameLower> === null) | ||
throw new Error("The parameter '<parameter.VariableNameLower>' must be defined."); | ||
else | ||
<endif> | ||
<if(parameter.IsDate)> | ||
<if(parameter.IsArray)> | ||
<parameter.VariableNameLower>.forEach(item => { url += "<parameter.Name>=" + encodeURIComponent("" + item.toJSON()) + "&"; \}); | ||
<else> | ||
url += "<parameter.Name>=" + encodeURIComponent("" + <parameter.VariableNameLower>.toJSON()) + "&"; | ||
<endif> | ||
<else> | ||
<if(parameter.IsArray)> | ||
<parameter.VariableNameLower>.forEach(item => { url += "<parameter.Name>=" + encodeURIComponent("" + item) + "&"; \}); | ||
<else> | ||
url += "<parameter.Name>=" + encodeURIComponent("" + <parameter.VariableNameLower>) + "&"; | ||
<endif> | ||
<endif> | ||
}> | ||
|
||
<if(operation.HasContent)> | ||
var content = JSON.stringify(<operation.ContentParameter.VariableNameLower>); | ||
<else> | ||
var content = ""; | ||
<endif> | ||
|
||
return this.http({ | ||
url: url, | ||
method: "<operation.HttpMethodUpper>", | ||
data: content, | ||
transformResponse: [], | ||
headers: { | ||
<operation.HeaderParameters:{parameter | | ||
"<parameter.Name>": <parameter.VariableNameLower>, | ||
}> "Content-Type": "application/json; charset=UTF-8" | ||
\} | ||
\}).then((response) => { | ||
return this.process<operation.OperationNameUpper>(response); | ||
\}); | ||
\} | ||
|
||
private process<operation.OperationNameUpper>(response: any) { | ||
var data = response.data; | ||
var status = response.status; | ||
|
||
<operation.Responses:{response | | ||
if (status === <response.StatusCode>) { | ||
<if(response.HasType)> | ||
var result<response.StatusCode>: <response.Type> = null; | ||
<if(response.IsDate)> | ||
result<response.StatusCode> = new Date(data); | ||
<else> | ||
result<response.StatusCode> = \<<response.Type>>JSON.parse(data, this.jsonParseReviver); | ||
<endif> | ||
<if(response.IsSuccess)> | ||
return result<response.StatusCode>; | ||
<else> | ||
throw result<response.StatusCode>; | ||
<endif> | ||
<endif> | ||
\} | ||
else}> | ||
{ | ||
<if(operation.HasDefaultResponse)> | ||
var result: <operation.DefaultResponse.Type> = null; | ||
<if(operation.DefaultResponse.IsDate)> | ||
result = new Date(data); | ||
<else> | ||
result = \<<operation.DefaultResponse.Type>>JSON.parse(data, this.jsonParseReviver); | ||
<endif> | ||
<if(operation.DefaultResponse.IsSuccess)> | ||
return result; | ||
<else> | ||
throw result; | ||
<endif> | ||
<else> | ||
throw "error_no_callback_for_the_received_http_status"; | ||
<endif> | ||
\} | ||
\} | ||
}>} | ||
<endif> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters