Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[csharp-netcore]: Adding http response details in api_docs and making example snippet compilable #3128

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Then, publish to a [local feed](https://docs.microsoft.com/en-us/nuget/hosting-p
## Getting Started

```csharp
using System;
using System.Collections.Generic;
using System.Diagnostics;
using {{packageName}}.{{apiPackage}};
using {{packageName}}.Client;
Expand All @@ -90,9 +90,10 @@ namespace Example
{
public class {{operationId}}Example
{
public void main()
public static void Main()
{
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
Configuration.Default.BasePath = "{{{basePath}}}";
{{#hasAuthMethods}}
{{#authMethods}}
{{#isBasic}}
Expand All @@ -113,7 +114,7 @@ namespace Example
{{/authMethods}}

{{/hasAuthMethods}}
var apiInstance = new {{classname}}();
var apiInstance = new {{classname}}(Configuration.Default);
{{#allParams}}
{{#isPrimitiveType}}
var {{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}}{{^required}} (optional) {{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
Expand All @@ -128,12 +129,14 @@ namespace Example
{{#summary}}
// {{{.}}}
{{/summary}}
{{#returnType}}{{{.}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saigiridhar21 FYI. the {{{.}}} is default to the value of the mustache tag

Debug.WriteLine(result);{{/returnType}}
}
catch (Exception e)
catch (ApiException e)
{
Debug.Print("Exception when calling {{classname}}.{{operationId}}: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Method | HTTP request | Description
{{#operation}}
<a name="{{{operationIdLowerCase}}}"></a>
# **{{{operationId}}}**
> {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}} ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = null{{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
> {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}} ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = null{{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})

{{{summary}}}{{#notes}}

{{{notes}}}{{/notes}}

### Example
```csharp
using System;
using System.Collections.Generic;
using System.Diagnostics;
using {{packageName}}.{{apiPackage}};
using {{packageName}}.Client;
Expand All @@ -30,8 +30,9 @@ namespace Example
{
public class {{operationId}}Example
{
public void main()
public static void Main()
{
Configuration.Default.BasePath = "{{{basePath}}}";
{{#hasAuthMethods}}
{{#authMethods}}
{{#isBasic}}
Expand All @@ -52,7 +53,7 @@ namespace Example
{{/authMethods}}

{{/hasAuthMethods}}
var apiInstance = new {{classname}}();
var apiInstance = new {{classname}}(Configuration.Default);
{{#allParams}}
{{#isPrimitiveType}}
var {{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}}{{^required}} (optional) {{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
Expand All @@ -67,12 +68,14 @@ namespace Example
{{#summary}}
// {{{.}}}
{{/summary}}
{{#returnType}}{{returnType}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
Debug.WriteLine(result);{{/returnType}}
}
catch (Exception e)
catch (ApiException e)
{
Debug.Print("Exception when calling {{classname}}.{{operationId}}: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
Expand All @@ -88,7 +91,7 @@ Name | Type | Description | Notes

### Return type

{{#returnType}}{{#returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{{returnType}}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void (empty response body){{/returnType}}
{{#returnType}}{{#returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{returnType}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void (empty response body){{/returnType}}

### Authorization

Expand All @@ -99,6 +102,15 @@ Name | Type | Description | Notes
- **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
- **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}}

{{#responses.0}}
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
{{#responses}}
| **{{code}}** | {{message}} | {{#headers}} * {{baseName}} - {{description}} <br> {{/headers}}{{^headers.0}} - {{/headers.0}} |
{{/responses}}
{{/responses.0}}

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

{{/operation}}
Expand Down
11 changes: 7 additions & 4 deletions samples/client/petstore/csharp-netcore/OpenAPIClient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ using Org.OpenAPITools.Model;
## Getting Started

```csharp
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
Expand All @@ -58,10 +58,11 @@ namespace Example
{
public class Example
{
public void main()
public static void Main()
{

var apiInstance = new AnotherFakeApi();
Configuration.Default.BasePath = "http://petstore.swagger.io:80/v2";
var apiInstance = new AnotherFakeApi(Configuration.Default);
var body = new ModelClient(); // ModelClient | client model

try
Expand All @@ -70,9 +71,11 @@ namespace Example
ModelClient result = apiInstance.Call123TestSpecialTags(body);
Debug.WriteLine(result);
}
catch (Exception e)
catch (ApiException e)
{
Debug.Print("Exception when calling AnotherFakeApi.Call123TestSpecialTags: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ To test special tags and operation ID starting with number

### Example
```csharp
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
Expand All @@ -27,9 +27,10 @@ namespace Example
{
public class Call123TestSpecialTagsExample
{
public void main()
public static void Main()
{
var apiInstance = new AnotherFakeApi();
Configuration.Default.BasePath = "http://petstore.swagger.io:80/v2";
var apiInstance = new AnotherFakeApi(Configuration.Default);
var body = new ModelClient(); // ModelClient | client model

try
Expand All @@ -38,9 +39,11 @@ namespace Example
ModelClient result = apiInstance.Call123TestSpecialTags(body);
Debug.WriteLine(result);
}
catch (Exception e)
catch (ApiException e)
{
Debug.Print("Exception when calling AnotherFakeApi.Call123TestSpecialTags: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
Expand All @@ -66,5 +69,10 @@ No authorization required
- **Content-Type**: application/json
- **Accept**: application/json

### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | successful operation | - |

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

Loading