Azure / Azure/azure-functions-openapi-extension
Validation based on OpenApiExampleAttribute?
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
The OpenAPI extension lets you define how a body should look like. ([OpenApiExampleAttribue](https://github.com/Azure/azure-functions-openapi-extension/blob/main/docs/openapi-core.md#openapiexampleattribute))
This could look like that:
```csharp
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
namespace DiamAPI.Models;
[OpenApiExample(typeof(CatExample))]
public class Cat
{
public int Id { get; set; }
[OpenApiProperty(Nullable = false, Default = "Nabi", Description = "The name your cat does not listen to.")]
public string Name { get; set; }
public CatBreed Breed { get; set; }
}
[JsonConverter(typeof(StringEnumConverter))]
public enum CatBreed
{
[Display("Siamese")]
Siamese = 0,
[Display("Maine Coon")]
MaineCoon = 1,
[Display("Persian")]
Persian = 2,
}
public class CatExample : OpenApiExample
{
public override IOpenApiExample Build(NamingStrategy namingStrategy = null)
{
Examples.Add(OpenApiExampleResolver.Resolve("nabi", new Cat() { Id = 123, Name = "Nabi", Breed = CatBreed.Siamese }, namingStrategy));
return this;
}
}
```
Is there any way to validate the body against this schema? Right now this only serves to have a nice UI and nothing more, but I hope I overlooked something.

Contributor guide
Assessment
This issue has not been assessed yet.