Skip to content

Commit

Permalink
[csharp-netcore]: Adding http response details in api_docs and making…
Browse files Browse the repository at this point in the history
… example snippet compilable (#3128)

* feat(csharp-documentation): Improving documentation and example

* feat(csharp-documentation): Updating pet project

* feat(csharp-documentation): Minor updates

* feat(csharp-documentation): Updating pet project

* feat(csharp): Updating pet project

* feat(csharp-netcore): Updating pet project
  • Loading branch information
saigiridhar21 authored and wing328 committed Jun 21, 2019
1 parent b9451e9 commit 2a5af92
Show file tree
Hide file tree
Showing 16 changed files with 961 additions and 324 deletions.
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}}
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

0 comments on commit 2a5af92

Please sign in to comment.