question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Errors in OpenApiDocument.FromUrlAsync when the web server requires a user-agent

See original GitHub issue

I’m trying to generate a client for a government API that has their server configured to reject requests that do not specify a User-Agent header. This seems like an odd thing to do, but I guess they are trying to track usage or detect abuse via that header.

Our workaround is to download the spec and generate from a file, but it would be nice to not need that.

I think we could fix this by specifying a header in DynamicApis before we make the request, but I’m unclear why we use DynamicApis instead of HttpClient directly.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jeremyVignellescommented, Jul 23, 2020

Not sure there is something to add here in NSwag. If an option was introduced for setting the user agent, then others wouldn’t understand :

  • why the header X is not allowed
  • why basic authentication is not supported…
  • why they can’t contact a website with a self-signed certificate

I’d argue to keep the project and options simple, and for complex scenarios like these, download the file with a curl, a dotnet-script, a console app or whatever, and pass that file to NSwag.

0reactions
ryepupcommented, Sep 29, 2020

Closing this out, there are options to solve the problem outside nswag and all the proposed solutions open up pandora’s box to endless scope/feature creep.

Thanks for consideration @RicoSuter and for the great counterpoint @jeremyVignelles.

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# (CSharp) OpenApiDocument Examples
C# (CSharp) OpenApiDocument - 33 examples found. These are the top rated real world C# (CSharp) examples of OpenApiDocument extracted from open source ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found