We are migrating an Azure Function app from .NET Framework 4.8 to .NET 6.0.
The old version uses several custom attributes on the model properties to control what is shown in the generated swagger OpenAPI 2.0 documentation - including "Required" and "Readonly".
For example, when generating the swagger docs when a model has both read/create operations, it uses the readonly attribute to "hide" the properties that are not accepted on create. The same property is not hidden on the read call, since the server has populated it at that point.
The new function app is using the provided Microsoft.Azure.WebJobs.Extensions.OpenApi extension to generate the OpenAPI 3.0 docs and we want to find a way to add this same "readonly" functionality.
Does anyone have an idea on how this could be done?
An example model from the old application:
public class ThingModel
{
[Display(Name = "Thing Id", Description = "Thing Model Id")]
[ReadOnly(true)]
public Guid? Id { get; set; }
[Display(Name = "Thing Name", Description = "Name of Thing")]
[Attributes.Required(HttpMethodType.Post)]
public string Name { get; set; }
[Display(Name = "Thing Description", Description = "Description of Thing")]
public string Description { get; set; }
}
The documentation for the nuget package has many attributes defined, but "readonly" is not one of them: https://github.com/Azure/azure-functions-openapi-extension/blob/main/docs/openapi-core.md
