OpenAPITools / OpenAPITools/openapi-generator
[BUG] README.md file shows incorrect usage of `ConfigureApi`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When generating a C# client using OpenAPI Generator version 7.12.0, the README.md file produced alongside the generated code shows an incorrect usage example of the ConfigureApi method for setting up the API client.
The README provides the following sample code:
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
.ConfigureApi((context, options) =>
{
options.ConfigureJsonOptions(jsonOptions =>
{
// your custom converters if any
});
options.AddApiHttpClients(builder => builder
.AddRetryPolicy(2)
.AddTimeoutPolicy(TimeSpan.FromSeconds(5))
.AddCircuitBreakerPolicy(10, TimeSpan.FromSeconds(30))
);
});
However, this results in a compile-time error:
CS1503: Argument 2: cannot convert from 'lambda expression' to 'Action<HostBuilderContext, IServiceCollection, HostConfiguration>'
The actual generated code in IHostBuilderExtensions.cs includes this method signature:
public static IHostBuilder ConfigureApi(this IHostBuilder builder, Action<HostBuilderContext, IServiceCollection, HostConfiguration> options) { ... }
That is, the lambda passed to ConfigureApi must accept three parameters, not two. This is further confirmed by the generator's own output: the unit tests use the correct lambda signature:
.ConfigureApi((context, services, options) =>
{
// configuration here...
});
The README example should therefore be updated to the following:
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
.ConfigureApi((context, services, options) =>
{
options.ConfigureJsonOptions(jsonOptions =>
{
// your custom converters if any
});
options.AddApiHttpClients(builder => builder
.AddRetryPolicy(2)
.AddTimeoutPolicy(TimeSpan.FromSeconds(5))
.AddCircuitBreakerPolicy(10, TimeSpan.FromSeconds(30))
);
});
openapi-generator version
7.12.0 (latest release at time of writing)
OpenAPI declaration file content or url
Not applicable – issue concerns structure of generated setup code
Generation Details
- Language: C#
- Target: HTTP API client generation
- Environment: .NET 8
- Configuration: Default
Steps to reproduce
- Generate a C# client using OpenAPI Generator 7.12.0.
- Use the README-provided
ConfigureApiexample in an ASP.NET Core application. - Attempt to compile the application.
- Compilation fails due to mismatched lambda delegate signature.
Related issues/PRs
None found after searching open issues.
Suggest a fix
Update the README.md to show the correct lambda signature using three parameters: (HostBuilderContext, IServiceCollection, HostConfiguration). This change will align the example with both the generated extension method signature and the generated test code, and prevent compile-time errors for users following the example.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the C# generator template that produces README.md and compare its ConfigureApi example with IHostBuilderExtensions.cs and the generator tests, which show the three-parameter signature. Update the README example to match the generated API, then run the relevant C# generator tests or regenerate a client to verify the documentation compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100