Skip to content

Commit

Permalink
updated plugins for AXIOS, Fetch API and Aurelia.
Browse files Browse the repository at this point in the history
  • Loading branch information
zijianhuang committed Mar 20, 2024
1 parent c310f34 commit 14de0b4
Show file tree
Hide file tree
Showing 61 changed files with 555 additions and 555 deletions.
18 changes: 9 additions & 9 deletions OpenApiClientGenCore.Aurelia/ClientApiTsAureliaFunctionGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,19 @@ protected override void RenderImplementation()
{
if (httpMethodName == "get" || httpMethodName == "delete")
{
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, {OptionsForString}).then(d => d.text());")); //todo: type cast is not really needed.
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, {OptionsForString}).then(d => {{if (d.status<=204) return d.text(); throw d;}});")); //todo: type cast is not really needed.
return;
}

if (httpMethodName == "post" || httpMethodName == "put" || httpMethodName == "patch")
{
if (RequestBodyCodeTypeReference == null)
{
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, null, {OptionsForString}).then(d => d.text());"));
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, null, {OptionsForString}).then(d => {{if (d.status<=204) return d.text(); throw d;}});"));
}
else
{
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, JSON.stringify(requestBody), {ContentOptionsForString}).then(d => d.text());"));
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, JSON.stringify(requestBody), {ContentOptionsForString}).then(d => {{if (d.status<=204) return d.text(); throw d;}});"));
}

return;
Expand All @@ -141,19 +141,19 @@ protected override void RenderImplementation()
{
if (httpMethodName == "get" || httpMethodName == "delete")
{
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, {OptionsForResponse}).then(d => d.json());"));
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, {OptionsForResponse}).then(d => {{if (d.status<=204) return d.json(); throw d;}});"));
return;
}

if (httpMethodName == "post" || httpMethodName == "put" || httpMethodName == "patch")
{
if (RequestBodyCodeTypeReference == null)
{
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, null, {OptionsForResponse}).then(d => d.json());"));
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, null, {OptionsForResponse}).then(d => {{if (d.status<=204) return d.json(); throw d;}});"));
}
else
{
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, JSON.stringify(requestBody), {ContentOptionsForResponse}).then(d => d.json());"));
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, JSON.stringify(requestBody), {ContentOptionsForResponse}).then(d => {{if (d.status<=204) return d.json(); throw d;}});"));
}

return;
Expand Down Expand Up @@ -195,7 +195,7 @@ protected override void RenderImplementation()
}
else
{
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, {Options}).then(d => d.json());"));
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, {Options}).then(d => {{if (d.status<=204) return d.json(); throw d;}});"));
}
}
else if (httpMethodName == "post" || httpMethodName == "put" || httpMethodName == "patch")
Expand All @@ -215,11 +215,11 @@ protected override void RenderImplementation()
{
if (RequestBodyCodeTypeReference == null) // no body
{
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, null, {Options}).then(d => d.json());"));
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, null, {Options}).then(d => {{if (d.status<=204) return d.json(); throw d;}});"));
}
else
{
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, JSON.stringify(requestBody), {OptionsWithContent}).then(d => d.json());"));
Method.Statements.Add(new CodeSnippetStatement($"return this.http.{httpMethodName}({uriText}, JSON.stringify(requestBody), {OptionsWithContent}).then(d => {{if (d.status<=204) return d.json(); throw d;}});"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/zijianhuang/openapiclientgen</PackageProjectUrl>
<NeutralLanguage>en</NeutralLanguage>
<Version>2</Version>
<Version>2.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions OpenApiClientGenCore.Axios/ClientApiTsAxiosFunctionGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,19 @@ protected override void RenderImplementation()
{
if (httpMethodName == "get" || httpMethodName == "delete")
{
Method.Statements.Add(new CodeSnippetStatement($"return Axios.{httpMethodName}({uriText}, {OptionsForString}).then(d => d.data);")); //todo: type cast is not really needed.
Method.Statements.Add(new CodeSnippetStatement($"return Axios.{httpMethodName}({uriText}, {OptionsForString}).then(d => {{if (d.status<=204) return d.data); throw d;}});")); //todo: type cast is not really needed.
return;
}

if (httpMethodName == "post" || httpMethodName == "put" || httpMethodName == "patch")
{
if (RequestBodyCodeTypeReference == null)
{
Method.Statements.Add(new CodeSnippetStatement($"return Axios.{httpMethodName}({uriText}, null, {OptionsForString}).then(d => d.data);"));
Method.Statements.Add(new CodeSnippetStatement($"return Axios.{httpMethodName}({uriText}, null, {OptionsForString}).then(d => {{if (d.status<=204) return d.data); throw d;}});"));
}
else
{
Method.Statements.Add(new CodeSnippetStatement($"return Axios.{httpMethodName}({uriText}, JSON.stringify(requestBody), {ContentOptionsForString}).then(d => d.data);"));
Method.Statements.Add(new CodeSnippetStatement($"return Axios.{httpMethodName}({uriText}, JSON.stringify(requestBody), {ContentOptionsForString}).then(d => {{if (d.status<=204) return d.data); throw d;}});"));
}

return;
Expand Down Expand Up @@ -195,7 +195,7 @@ protected override void RenderImplementation()
}
else
{
Method.Statements.Add(new CodeSnippetStatement($"return Axios.{httpMethodName}{returnTypeCast}({uriText}, {Options}).then(d => d.data);"));
Method.Statements.Add(new CodeSnippetStatement($"return Axios.{httpMethodName}{returnTypeCast}({uriText}, {Options}).then(d => {{if (d.status<=204) return d.data); throw d;}});"));
}
}
else if (httpMethodName == "post" || httpMethodName == "put" || httpMethodName == "patch")
Expand All @@ -215,11 +215,11 @@ protected override void RenderImplementation()
{
if (RequestBodyCodeTypeReference == null) // no body
{
Method.Statements.Add(new CodeSnippetStatement($"return Axios.{httpMethodName}{returnTypeCast}({uriText}, null, {Options}).then(d => d.data);"));
Method.Statements.Add(new CodeSnippetStatement($"return Axios.{httpMethodName}{returnTypeCast}({uriText}, null, {Options}).then(d => {{if (d.status<=204) return d.data); throw d;}});"));
}
else
{
Method.Statements.Add(new CodeSnippetStatement($"return Axios.{httpMethodName}{returnTypeCast}({uriText}, JSON.stringify(requestBody), {OptionsWithContent}).then(d => d.data);"));
Method.Statements.Add(new CodeSnippetStatement($"return Axios.{httpMethodName}{returnTypeCast}({uriText}, JSON.stringify(requestBody), {OptionsWithContent}).then(d => {{if (d.status<=204) return d.data); throw d;}});"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/zijianhuang/openapiclientgen</PackageProjectUrl>
<NeutralLanguage>en</NeutralLanguage>
<Version>2</Version>
<Version>2.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions OpenApiClientGenCore.Fetch/ClientApiTsFetchFunctionGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,19 @@ protected override void RenderImplementation()
{
if (httpMethodName == "get" || httpMethodName == "delete")
{
Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {OptionsForString}).then(d => d.text());")); //todo: type cast is not really needed.
Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {OptionsForString}).then(d => {{if (d.status<=204) return d.status == 204 ? null : d.text(); throw d;}});")); //todo: type cast is not really needed.
return;
}

if (httpMethodName == "post" || httpMethodName == "put" || httpMethodName == "patch")
{
if (RequestBodyCodeTypeReference == null)
{
Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {OptionsForString}).then(d => d.text());"));
Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {OptionsForString}).then(d => {{if (d.status<=204) return d.status == 204 ? null : d.text(); throw d;}});"));
}
else
{
Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {ContentOptionsForString}).then(d => d.text());"));
Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {ContentOptionsForString}).then(d => {{if (d.status<=204) return d.status == 204 ? null : d.text(); throw d;}});"));
}

return;
Expand All @@ -131,15 +131,15 @@ protected override void RenderImplementation()
//{
// if (httpMethodName == "post" || httpMethodName == "put" || httpMethodName == "patch")
// {
// Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {OptionsForResponse}).then(d => d.text());"));
// Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {OptionsForResponse}).then(d => {{if (d.status<=204) return d.status == 204 ? null : d.text(); throw d;}});"));
// return;
// }

// if (httpMethodName == "post" || httpMethodName == "put" || httpMethodName == "patch")
// {
// if (RequestBodyCodeTypeReference == null)
// {
// Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, null, {OptionsForResponse}).then(d => d.text());"));
// Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, null, {OptionsForResponse}).then(d => {{if (d.status<=204) return d.status == 204 ? null : d.text(); throw d;}});"));
// }
// else
// {
Expand Down Expand Up @@ -185,7 +185,7 @@ protected override void RenderImplementation()
}
else
{
Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {Options}).then(d => d.json());"));
Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {Options}).then(d => {{if (d.status<=204) return d.json(); throw d;}});"));
}
}
else if (httpMethodName == "post" || httpMethodName == "put" || httpMethodName == "patch")
Expand All @@ -205,11 +205,11 @@ protected override void RenderImplementation()
{
if (RequestBodyCodeTypeReference == null) // no body
{
Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {Options}).then(d => d.json());"));
Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {Options}).then(d => {{if (d.status<=204) return d.json(); throw d;}});"));
}
else
{
Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {OptionsWithContent}).then(d => d.json());"));
Method.Statements.Add(new CodeSnippetStatement($"return fetch({uriText}, {OptionsWithContent}).then(d => {{if (d.status<=204) return d.json(); throw d;}});"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/zijianhuang/openapiclientgen</PackageProjectUrl>
<NeutralLanguage>en</NeutralLanguage>
<Version>2</Version>
<Version>2.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions Tests/SwagTsTests/AureliaResults/Pet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export namespace MyNS {
* @return {Pet} successful operation
*/
GetPetById(petId: string): Promise<Pet> {
return this.http.get('pet/' + petId, {}).then(d => d.json());
return this.http.get('pet/' + petId, {}).then(d => {if (d.status<=204) return d.json(); throw d;});
}

/**
Expand All @@ -243,7 +243,7 @@ export namespace MyNS {
* @return {Array<Pet>} successful operation
*/
FindPetsByStatus(status: Array<PetStatus>): Promise<Array<Pet>> {
return this.http.get('pet/findByStatus?' + status.map(z => `status=${z}`).join('&'), {}).then(d => d.json());
return this.http.get('pet/findByStatus?' + status.map(z => `status=${z}`).join('&'), {}).then(d => {if (d.status<=204) return d.json(); throw d;});
}

/**
Expand All @@ -254,7 +254,7 @@ export namespace MyNS {
* @return {Array<Pet>} successful operation
*/
FindPetsByTags(tags: Array<string>): Promise<Array<Pet>> {
return this.http.get('pet/findByTags?' + tags.map(z => `tags=${encodeURIComponent(z)}`).join('&'), {}).then(d => d.json());
return this.http.get('pet/findByTags?' + tags.map(z => `tags=${encodeURIComponent(z)}`).join('&'), {}).then(d => {if (d.status<=204) return d.json(); throw d;});
}
}

Expand All @@ -270,7 +270,7 @@ export namespace MyNS {
* @return {{[id: string]: number }} successful operation
*/
GetInventory(): Promise<{[id: string]: number }> {
return this.http.get('store/inventory', {}).then(d => d.json());
return this.http.get('store/inventory', {}).then(d => {if (d.status<=204) return d.json(); throw d;});
}

/**
Expand All @@ -280,7 +280,7 @@ export namespace MyNS {
* @return {Order} successful operation
*/
PlaceOrder(requestBody: Order): Promise<Order> {
return this.http.post('store/order', JSON.stringify(requestBody), { headers: { 'Content-Type': 'application/json;charset=UTF-8' } }).then(d => d.json());
return this.http.post('store/order', JSON.stringify(requestBody), { headers: { 'Content-Type': 'application/json;charset=UTF-8' } }).then(d => {if (d.status<=204) return d.json(); throw d;});
}

/**
Expand All @@ -292,7 +292,7 @@ export namespace MyNS {
* @return {Order} successful operation
*/
GetOrderById(orderId: string): Promise<Order> {
return this.http.get('store/order/' + orderId, {}).then(d => d.json());
return this.http.get('store/order/' + orderId, {}).then(d => {if (d.status<=204) return d.json(); throw d;});
}

/**
Expand Down Expand Up @@ -331,7 +331,7 @@ export namespace MyNS {
* @return {User} successful operation
*/
GetUserByName(username: string): Promise<User> {
return this.http.get('user/' + (username == null ? '' : encodeURIComponent(username)), {}).then(d => d.json());
return this.http.get('user/' + (username == null ? '' : encodeURIComponent(username)), {}).then(d => {if (d.status<=204) return d.json(); throw d;});
}

/**
Expand Down Expand Up @@ -385,7 +385,7 @@ export namespace MyNS {
* @return {string} successful operation
*/
LoginUser(username: string, password: string): Promise<string> {
return this.http.get('user/login?username=' + (username == null ? '' : encodeURIComponent(username)) + '&password=' + (password == null ? '' : encodeURIComponent(password)), {}).then(d => d.text());
return this.http.get('user/login?username=' + (username == null ? '' : encodeURIComponent(username)) + '&password=' + (password == null ? '' : encodeURIComponent(password)), {}).then(d => {if (d.status<=204) return d.text(); throw d;});
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Tests/SwagTsTests/AureliaResults/PetFindByStatus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export namespace MyNS {
* @return {Array<Pet>} successful operation
*/
FindPetsByStatus(status: Array<PetStatus>): Promise<Array<Pet>> {
return this.http.get('pet/findByStatus?' + status.map(z => `status=${z}`).join('&'), {}).then(d => d.json());
return this.http.get('pet/findByStatus?' + status.map(z => `status=${z}`).join('&'), {}).then(d => {if (d.status<=204) return d.json(); throw d;});
}

/**
Expand All @@ -105,7 +105,7 @@ export namespace MyNS {
* @return {Array<Pet>} successful operation
*/
FindPetsByStatus2(status: PetStatus): Promise<Array<Pet>> {
return this.http.get('pet/findByStatus2?status=' + status, {}).then(d => d.json());
return this.http.get('pet/findByStatus2?status=' + status, {}).then(d => {if (d.status<=204) return d.json(); throw d;});
}

/**
Expand All @@ -116,7 +116,7 @@ export namespace MyNS {
* @return {Array<Pet>} successful operation
*/
FindPetsByStatus3(status: PetStatus): Promise<Array<Pet>> {
return this.http.get('pet/findByStatus3?status=' + status, {}).then(d => d.json());
return this.http.get('pet/findByStatus3?status=' + status, {}).then(d => {if (d.status<=204) return d.json(); throw d;});
}
}

Expand Down
Loading

0 comments on commit 14de0b4

Please sign in to comment.