dependabot[bot] on nuget
Bump System.Net.Http from 4.3.2… (compare)
dependabot[bot] on nuget
Bump System.Net.Http in /src/NS… (compare)
dependabot[bot] on nuget
Bump System.Net.Http in /src/NS… (compare)
@RicoSuter - I'm reading the OpenAPI 3 spec, and -- If I'm understanding it correctly -- it does seem to support "objects" as query parameters https://swagger.io/docs/specification/describing-parameters/#query-parameters:
"Query parameters can be primitive values, arrays and objects"
Related to that is how query parameters can be serialized: https://swagger.io/docs/specification/serialization/
PrepareRequest
methods to add the bearer token? and on the ProduceResponse
for the login method to get and store the token?
@RicoSuter - I am able to reproduce my "home route" problem starting from the sample "SampleOwinWebApiWithSwaggerUi" found here: https://github.com/NSwag/Samples/tree/master/src . Steps: 1) Run the sample and confirm that the home page shows up. 2) Upgrade all NSwag NuGet packages to 13.9.4. 3) In Startup.cs, change the call "UseSwaggerUi" to
UseSwaggerUi3(typeof(Startup).Assembly, s =>
{
s.Path = "/foo";
s.SwaggerRoutes.Add(new SwaggerUi3Route("My Fancy API v1", "/qwerty/asdf.json"));
});
Now when you run the project, instead of the home page, you see that it has been "hijacked" by raw Swagger JSON.
I've being using the partial client to add my JWT bearer tokens, but for some reason they don't always get added. But I can't see why.
async partial void PrepareRequest(HttpClient client, HttpRequestMessage request, string url)
{
_logger.LogInformation($"Prepare Request: {request.RequestUri.AbsoluteUri}");
var user = await _storage.GetItem<LoginResult>("user");
if (user != null)
{
_logger.LogInformation($"Adding Auth Header: {user.UserName}, {user.JwtToken}");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", user.JwtToken);
}
}
I can see in the chrome log the 'Preparing Request' and 'Adding Auth Header' messages, but the request has none added...its like the client as fired off the request already?
DateTime
fields as the Blazor UI toolkit I'm using doesn't support the DateTimeOffset
type, but these fields are being passed back to the API. I've tried JsonIgnore
, doesn't seem to change things.
Hi. I am using Nswag and generating typescript API definition from an api that has the attribute [OpenApiBodyParameter("application/octet-stream")]
//[ValidateAntiForgeryToken]
public async Task<ActionResult> Upload()
However the generated api code specifies Blob instead of File
upload(body: Blob | null | undefined): Promise<FileResponse | null> {
which generates an error when trying to read the content-type boundary. is there any other attribute I should be using so it generates the api with File instead of Blob?
related: RicoSuter/NSwag#2493
content_.Add(new System.Net.Http.StringContent(ConvertToString(profile, System.Globalization.CultureInfo.InvariantCulture)), "profile");
content_.Add(new System.Net.Http.StringContent(ConvertToString(profile, System.Globalization.CultureInfo.InvariantCulture), System.Text.Encoding.UTF8, "application/json"), "profile");
as per the spec: https://swagger.io/specification/#special-considerations-for-multipart-content
If the property is complex, or an array of complex values, the default Content-Type is application/json
[Route("api/[controller]")]
[ApiController]
public class FruitController : ControllerBase
{
[HttpGet]
[Route("all")]
public ActionResult<IEnumerable<Fruit>> GetAll()
{
return Ok(new List<Fruit>(){
new Apple { Type = "apple", Color = "red" },
new Apple { Type = "apple", Color = "green" },
new Banana { Type = "banana", Age = 1 },
new Banana { Type = "banana", Age = 2 }
});
}
}
public class Fruit
{
public string Type { get; set; }
}
public class Banana : Fruit
{
public int Age { get; set; }
}
public class Apple : Fruit
{
public string Color { get; set; }
}
public class FruitConverter : JsonInheritanceConverter
{
public FruitConverter(string name) : base(name)
{
}
public override string GetDiscriminatorValue(Type type)
{
return type switch
{
{ } when type == typeof(Banana) => "banana",
{ } when type == typeof(Apple) => "apple",
_ => throw new NotImplementedException(),
};
}
protected override Type GetDiscriminatorType(JObject jObject, Type objectType, string discriminatorValue)
{
return discriminatorValue switch
{
"banana" => typeof(Banana),
"apple" => typeof(Apple)
};
}
}
That's the code I'm playing around with, yet the Banana
and Apple
are not added in the open API schema unless I add KnownType
to Fruit
. Also looks like even the converter will not add the discriminator in the open API unless via Attribute.
Using it like this will not work:
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.Converters.Add(new FruitConverter("type"));
})