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

IServiceCollectionExtensions extra closing parenthesis with httpMessageHandlers #205

Closed
EEParker opened this issue Oct 30, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@EEParker
Copy link

EEParker commented Oct 30, 2023

Describe the bug
Version 0.8.2 generates a new dependency injection IServiceCollectionExtensions, and seems to introduce a syntax error as shown below:

            services
                .AddRefitClient<IBackendApi>()
                .ConfigureHttpClient(c => c.BaseAddress = baseUrl)
                .AddHttpMessageHandler<AuthorizationMessageHandler>()
                .AddHttpMessageHandler<TelemetryMessageHandler>()); // extra ) here

This seems to originate from this line

I wasn't sure if there were use cases that this worked, but this is the config that does not work, and probably has something to do with the httpMessageHandlers in the dependency injection section.

{
    "openApiPath": "../../Services/BackendApi/wwwroot/swaggerfile.json",
    "namespace": "App.Services.Clients.BackendApiClient",
    "naming": {
      "useOpenApiTitle": false,
      "interfaceName": "BackendApiClient"
    },
    "generateContracts": true,
    "generateXmlDocCodeComments": true,
    "addAutoGeneratedHeader": false,
    "addAcceptHeaders": false,
    "returnIApiResponse": true,
    "generateOperationHeaders": true,
    "typeAccessibility": 0,
    "useCancellationTokens": false,
    "useIsoDateFormat": true,
    "multipleInterfaces": 2,
    "generateDeprecatedOperations": false,
    "operationNameTemplate": "{operationName}Async",
    "optionalParameters": true,
    "outputFolder": "./Clients",
    "includePathMatches": [
      "^(?!.*[Ii]ntegration[Ee]vent).*\/api.*"
     ],
    "dependencyInjectionSettings": {
      "httpMessageHandlers": [
          "AuthorizationMessageHandler",
          "TelemetryMessageHandler"
      ]
    }
  }

I cannot include the API spec for privacy reasons.

@EEParker EEParker added the bug Something isn't working label Oct 30, 2023
@christianhelle
Copy link
Owner

@EEParker Good catch!!

My (and my team's) use case is

  "dependencyInjectionSettings": {
    "baseUrl": "https://petstore3.swagger.io/api/v3",
    "usePolly": true,
    "pollyMaxRetryCount": 3,
    "firstBackoffRetryInSeconds": 0.5,
    "httpMessageHandlers": [
      "AuthorizationMessageHandler",
      "TelemetryMessageHandler"
    ]
  }

I never tested without using Polly! I'll fix this immediately. Sorry for the inconvenience.

@christianhelle
Copy link
Owner

@all-contributors please add @EEParker for bugs

@allcontributors
Copy link
Contributor

@christianhelle

I've put up a pull request to add @EEParker! 🎉

@EEParker
Copy link
Author

Thank you for the response and quick fix! Just FYI, our use case is Dapr service invocation which has retry and backoff, so we haven't implemented Polly. Thank you for creating and maintain this tool.

@christianhelle
Copy link
Owner

christianhelle commented Oct 31, 2023

The fix is on its way to a release and will be included in v0.8.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants