Doc failing to generate multiple actions single operation - c#

I was wondering if anyone has come across a workaround when using Swagger / Swashbuckle 5.0.1 to document a single operation which can have multiple actions against it. For example, take the following:
api/products
api/products?productType='cheese'
When attempting to generate the docs I get an error suggesting this is not supported. However, the Swagger docs suggest there is a workaround by doing a merge.
I don't understand what they mean by this and how to go about doing it. Can anyone provide any information?
The only workaround I have been able to find as suggested in their documentation is to do the following (resolve using the first entry):
c.ResolveConflictingActions(x => x.First());
This isn't ideal as from an API perspective I want all the variations present / visible.

As stated in Swashbuckle SwaggerConfig.cs file on this setting:
In contrast to WebApi, Swagger 2.0 does not include the query string
component when mapping a URL
This is not a Web API issue here, Swagger 2.0 spec does not actually support having query parameters.

Related

How to trigger HTTP requests based on OpenAPI .json files?

I'm looking for a way to interpret an OpenAPI .json definition. This is my workflow:
The user provides the .json file during runtime.
I would like to show all existing endpoints, their HTTP methods, parameters and expected bodies like e.g. Postman or Swagger are doing it.
The user can choose one endpoint and an HTTP method, then provide all needed parameters and send a request. As soon as I retrieve the response I will show it as plain text to the user.
The user can choose an endpoint and HTTP method and I will serialize the information needed to do step 3. later again without reading the whole .json file again.
I googled and tested a few libraries but did not find one or multiple which do exactly what I'm looking for.
I think OpenAPI.NET might do the reading job necessary for step 2.
Regarding the part that's able to trigger the HTTP request I only found fully-fledged "Client Creators" which take an OpenAPI .json and create C# code which can then be compiled to get a full client library. Many of these "Client Creators" are also build up on other tech stacks (e.g. Java) and make it difficult to use from a .Net application.
I had a deeper look into NSwag which is written in C# and can be installed as a NuGet but again this one creates C# code that needs to be compiled and it also seems it creates way more then I need (deserialization and handling of Non-OK status codes etc.)
I would just need a way to create something like a System.Net.Http.HttpRequestMessage or RestSharp.RestRequest. I could have a look into what it needs to create them by my own but I fear to reinvent the wheel and miss some more specific parts of the OpenAPI specification.
Do you know any libraries that would help me achieving my workflow but especially step 3 and step 4 of it?

.NET Core WEB API Modelbinding: how to make use of JSON Schema validation

I have a JSON Schema and want to make use of it iny my PUT/POST/PATCH API endpoints.
Basically I want to make use of JSON Schema validation and handle invalid JSON in the Http request pipeline.
I did not findy anything on the internet on that matter so I start thinking that I might missunderstood something essential here.
I assumed I could register Json Schema with options as middleware in startup but well, how can this be done ?
You'll want to check out OpenAPI -- it provides the specification that builds on top of JSON Schema to enable request and response validation, document generation, code generation, and lots more.
Also see https://github.com/OAI/OpenAPI-Specification/blob/main/IMPLEMENTATIONS.md for a list of implementations (although there are many more out there that aren't listed, too).
In a previous version of the site, I used this middleware for https://json-everything.net, which is my showcase site for my JSON library suite. It's powered by JsonSchema.Net, which itself is part of the suite.
It's likely not the best way to do it, but it works well. I'm still playing with it before I put it into a library, but you're welcome to copy it for your uses.

Unable to inject javascript into Swagger documentation

So I've seen this question posed before, but I feel like I have a specific context that warrants posing the question. I could be risking getting a good ol' stack overflow scolding, but here goes. In either case, I feel like it's going to likely be a one-line fix, so I'm prepared to be humbled. Quick profile of the system:
AspNetCore: 2.2.0
Swashbuckle: 4.0.1
Filename: ./SwaggerExtensions/test.js (only trying to get a console log verification at this point)
Inside Configure Method
app.UseSwaggerUI(o =>
{
o.SwaggerEndpoint($"/docs/swagger.json", $"{ApplicationName} {_applicationVersion}");
o.InjectJavascript("identity.SwaggerExtensions.test.js");
});
Additionally, I have invoked the UseStaticFiles middleware at the top of the Configure method. I have seen other implementations that require the use of the specific assembly (e.g. SwaggerConfig), but the version I'm using only calls for the 'logical name' of the file path (appName.directory.filename.type), but the InjectJavascript method for the version I'm using has no parameter for the assembly, only the file and an optional parameter for the type (e.g., text/javascript):
I feel like I've followed other posts about this pretty closely and I can't seem to make any headway on what appears to be a pretty straightforward implementation.
Additionally, the js file is being appended to the head of the html, but I imagine the format should be converted to a regular path. I have also set the Build Action to Embedded Resource. I feel like I've been chasing my tail for the last day or so trying to get this working so I can move on to implementing an auth flow.

.Net 2.0 HttpUtility.UrlEncode issue

I am working with a project in .Net 2.0, this must stay in .Net 2.0 I have no way around this as this is what the customer wants.
I am trying to create a string that is going to url encode this
HttpUtility.UrlEncode(key);
However, I get the message
HttpUtility does not contain a definition for UrlEncode
Looking at MSDN here https://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode(v=vs.80).aspx I see that this should be easily possible.
I have my using statement bringing in System.Web and it is in my references too.
Any ideas on what I need to do?
If you are having trouble with system.web use the alternate method as shown in this blog. Html-and-Uri-String-Encoding-without-SystemWeb

.net wrapper for OData to access any data source

I am looking for an OData wrapper in C# that can talk to any OData datasource and return the result as properties instead of the raw XML. I looked at http://odata.codeplex.com/ but it is designed around the concept of pointing to a specific datasource and building code that maps to it.
We need to create code where at runtime we are pointed to an OData datasource and read the metadata and then interactively call it with queries and then use the returned data. (I also believe Linq won't work for us because we have end users creating queries once we connect - no writing code and compiling.)
Is there anything out there?
thanks - dave
I assume you want to consume arbitrary OData service as a client, right? For that I would suggest using ODataLib (http://www.nuget.org/packages/Microsoft.Data.OData). It is a reader and writer for OData, nothing more. So it will require more code from you as compared to the WCF Data Services, but it allows consuming arbitrary OData payloads without the necessity to generate the matching types. You might also want to check out this blog for the start: http://blogs.msdn.com/b/astoriateam/archive/2011/10/14/introducing-the-odata-library.aspx
You might have to write a custom provider for what you are trying to achieve.
The following blog series are pretty helpful:
http://blogs.msdn.com/b/alexj/archive/2010/01/07/data-service-providers-getting-started.aspx
http://blogs.msdn.com/b/vitek/archive/2010/02/25/data-services-expressions-part-1-intro.aspx

Categories