Skip to content

Commit

Permalink
Merge pull request #66 from NSwag/master
Browse files Browse the repository at this point in the history
Release v2.8
  • Loading branch information
RicoSuter committed Apr 21, 2016
2 parents a6d777c + f9f0e15 commit c7a5385
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 149 deletions.
2 changes: 1 addition & 1 deletion src/NSwag.Annotations/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag.Annotations")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.7.*")]
[assembly: AssemblyVersion("2.8.*")]
2 changes: 1 addition & 1 deletion src/NSwag.CodeGeneration.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("2.7.*")]
// [assembly: AssemblyVersion("2.8.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{
<if(response.IsFile)>
var data = response.blob();
<else>
var text = response.text().replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \});
var data = JSON.parse(text, this.jsonParseReviver);
var data = JSON.parse(response.text(), this.jsonParseReviver);
<endif>
var status = response.status.toString();

Expand Down
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>

Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{
<if(response.IsFile)>
result<response.StatusCode> = data;
<else>
result<response.StatusCode> = data === "" ? null : \<<response.Type>>jQuery.parseJSON(
data.replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \}));
result<response.StatusCode> = data === "" ? null : \<<response.Type>>jQuery.parseJSON(data);
<endif>
<endif>
\} catch(e) {
Expand Down Expand Up @@ -139,8 +138,7 @@ export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{
<if(response.IsFile)>
result = data;
<else>
result = \<<operation.DefaultResponse.Type>>jQuery.parseJSON(
data.replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \}));
result = \<<operation.DefaultResponse.Type>>jQuery.parseJSON(data);
<endif>
<endif>
\} catch(e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{
<if(response.IsFile)>
result<response.StatusCode> = data;
<else>
result<response.StatusCode> = data === "" ? null : \<<response.Type>>jQuery.parseJSON(
data.replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \}));
result<response.StatusCode> = data === "" ? null : \<<response.Type>>jQuery.parseJSON(data);
<endif>
<endif>
\} catch(e) {
Expand Down Expand Up @@ -145,8 +144,7 @@ export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{
<if(response.IsFile)>
result = data;
<else>
result = \<<operation.DefaultResponse.Type>>jQuery.parseJSON(
data.replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \}));
result = \<<operation.DefaultResponse.Type>>jQuery.parseJSON(data);
<endif>
<endif>
\} catch(e) {
Expand Down
2 changes: 1 addition & 1 deletion src/NSwag.CodeGeneration/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag.CodeGeneration")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.7.*")]
[assembly: AssemblyVersion("2.8.*")]
2 changes: 1 addition & 1 deletion src/NSwag.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.7.*")]
[assembly: AssemblyVersion("2.8.*")]
2 changes: 1 addition & 1 deletion src/NSwag.Demo.Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("2.7.*")]
// [assembly: AssemblyVersion("2.8.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
2 changes: 1 addition & 1 deletion src/NSwag.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("2.7.*")]
// [assembly: AssemblyVersion("2.8.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
2 changes: 1 addition & 1 deletion src/NSwag/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwag.Console")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.7.*")]
[assembly: AssemblyVersion("2.8.*")]
2 changes: 1 addition & 1 deletion src/NSwagStudio/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Rico Suter")]
[assembly: AssemblyProduct("NSwagStudio")]
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
[assembly: AssemblyVersion("2.7.*")]
[assembly: AssemblyVersion("2.8.*")]

0 comments on commit c7a5385

Please sign in to comment.