添加项目文件。

This commit is contained in:
luoyunchong
2020-08-09 14:50:47 +08:00
parent 5d21b53ae2
commit 483c410943
51 changed files with 2367 additions and 0 deletions

View File

@ -0,0 +1,18 @@
using System;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace Basic.Swagger
{
public class AddCartsByIdGetExternalDocs : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
operation.ExternalDocs = new OpenApiExternalDocs
{
Description = "External docs for CartsByIdGet",
Url = new Uri("https://tempuri.org/carts-by-id-get")
};
}
}
}

View File

@ -0,0 +1,14 @@
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace Basic.Swagger
{
public class AssignOperationVendorExtensions : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
operation.Extensions.Add("x-purpose", new OpenApiString("test"));
}
}
}

View File

@ -0,0 +1,14 @@
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace Basic.Swagger
{
public class AssignRequestBodyVendorExtensions : IRequestBodyFilter
{
public void Apply(OpenApiRequestBody requestBody, RequestBodyFilterContext context)
{
requestBody.Extensions.Add("x-purpose", new OpenApiString("test"));
}
}
}

View File

@ -0,0 +1,31 @@
using System;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace Basic.Swagger
{
public class ExamplesSchemaFilter : ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
schema.Example = GetExampleOrNullFor(context.Type);
}
private IOpenApiAny GetExampleOrNullFor(Type type)
{
switch (type.Name)
{
case "Product":
return new OpenApiObject
{
[ "id" ] = new OpenApiInteger(123),
[ "description" ] = new OpenApiString("foobar"),
[ "price" ] = new OpenApiDouble(14.37)
};
default:
return null;
}
}
}
}