Skip to content

Commit

Permalink
Merge pull request #46 from ScottLogic/fixes
Browse files Browse the repository at this point in the history
A few minor fixes
  • Loading branch information
murcikan-scottlogic authored Jan 9, 2023
2 parents e232cee + 7195bdd commit 00431a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
26 changes: 26 additions & 0 deletions MyApp/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Swagger Petstore - OpenAPI 3.0 C# Client Library

This is an auto-generated client library for the Swagger Petstore - OpenAPI 3.0 API, via the `openapi-forge-csharp` template.

## Usage example

```csharp
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using OpenApiForge;

// perform any required configuration for accessing the API here
var config = new Configuration() { }

// register the API client with the DI container
var services = new ServiceCollection();
services.Add(new ServiceDescriptor(typeof(Configuration), config));
Startup.RegisterApiClient(services, config);

// get the API client from the DI container
var serviceProvider = services.BuildServiceProvider();
var api = serviceProvider.GetRequiredService<IApiClientPet>();

// perform an operation
var result = await api.findPetsByStatus(...);
```
20 changes: 3 additions & 17 deletions template/Configuration.cs.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,9 @@ using System.Text;

public virtual string GetBaseAddress()
{
var sb = RemoveTrailingSlash(new StringBuilder(Servers[SelectedServerIndex]));

if(!string.IsNullOrWhiteSpace(BasePath))
{
sb.Append(BasePath.StartsWith("/")
? BasePath
: $"/{BasePath}");
}

return RemoveTrailingSlash(sb).ToString();
}

private static StringBuilder RemoveTrailingSlash(StringBuilder sb)
{
return sb.Length > 0 && sb[sb.Length - 1] == '/'
? sb.Remove(sb.Length - 1, 1)
: sb;
var sb = new StringBuilder(BasePath);
sb.Append(Servers[SelectedServerIndex]);
return sb.ToString();
}
}
}

0 comments on commit 00431a9

Please sign in to comment.