Вот как я генерирую схему:
Код: Выделить всё
private OpenApiSchema GenerateSpecializedSchema(Type modelType, SchemaRepository schemaRepository, ISchemaGenerator schemaGenerator)
{
OpenApiSchema schema = schemaGenerator.GenerateSchema(modelType, schemaRepository);
// Schema is empty at this point
return schema;
}
Код: Выделить всё
public class MyCustomOperationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
// Retrieve the exact type I want from a custom attribute (details omitted for simplicity)
var modelType = ...;
// Generate the schema for the specified type
var schema = GenerateSpecializedSchema(modelType, context.SchemaRepository, context.SchemaGenerator);
}
}
Код: Выделить всё
public class MyClassExample
{
public string PropertyA { get; set; }
public string PropertyB { get; set; }
}
Полученный файл OAS JSON выглядит следующим образом: МойКлассПример:
Код: Выделить всё
...
"components": {
"schemas": {
"MyClassExample": {}
...
}
...
- Я отладил код, и кажется, что ISchemaGenerator.GenerateSchema возвращает результат пустая OpenApiSchema без каких-либо свойств.
- Я проверил, что modelType правильный и указывает на MyClassExample.
- Я проверил, что тип общедоступный и доступный.
Подробнее здесь: https://stackoverflow.com/questions/790 ... rates-an-e
Мобильная версия