Слайд 44Конфигурация Nswag.json
"runtime": "NetCore22",
"documentGenerator": { "webApiToOpenApi": {
"defaultUrlTemplate": "api/{controller}/{id?}",
"infoTitle": "PreviewStorage", "infoVersion":
"1.0.0",
"documentName": "v1","allowNullableBodyParameters": true,
"output": "../../api-docs/PreviewStorage_swagger.json",
"outputType": "OpenApi3",
"assemblyPaths": [
"../../bin/$(Configuration)/PreviewStorage/netcoreapp2.2/PreviewStorage.dll“ ], } },
"codeGenerators": {
"openApiToCSharpClient": { "input": "../../api-docs/PreviewStorage_swagger.json",
"namespace": "PreviewStorage.WebApiProxy",
"generateClientInterfaces": true,
"useHttpRequestMessageCreationMethod": true,
“httpClientType": "System.Net.Http.HttpClient",
"additionalNamespaceUsages": [ "PreviewService.Common.Model“ ],
"output": "../PreviewStorage.WebApiProxy/PreviewStorageProxy.g.cs",
"className": "{controller}PreviewStorageProxy",
"operationGenerationMode": "SingleClientFromOperationId“ } } }
Слайд 68Процессор
public class FileUploadOperationAttribute : OpenApiOperationProcessorAttribute {
public FileUploadOperationAttribute() : base(typeof(FileUploadOperationProcessor)) {
} }
public class FileUploadOperationProcessor : IOperationProcessor {
public bool Process(OperationProcessorContext context)
{
var parameters = context.OperationDescription.Operation.Parameters;
parameters.Add(new OpenApiParameter() {
Name = "stream", Kind = OpenApiParameterKind.Body,
Schema = new JsonSchema { Type = JsonObjectType.String, Format = "binary" },
IsRequired = true, Description = "Файл.",
});
return true; } }