mirror of
https://github.com/nsnail/IGeekFan.AspNetCore.Knife4jUI.git
synced 2025-08-03 13:07:59 +08:00
添加项目文件。
This commit is contained in:
18
test/Basic/Swagger/AddCartsByIdGetExternalDocs.cs
Normal file
18
test/Basic/Swagger/AddCartsByIdGetExternalDocs.cs
Normal 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")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
14
test/Basic/Swagger/AssignOperationVendorExtensions.cs
Normal file
14
test/Basic/Swagger/AssignOperationVendorExtensions.cs
Normal 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"));
|
||||
}
|
||||
}
|
||||
}
|
14
test/Basic/Swagger/AssignRequestBodyVendorExtensions.cs
Normal file
14
test/Basic/Swagger/AssignRequestBodyVendorExtensions.cs
Normal 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"));
|
||||
}
|
||||
}
|
||||
}
|
31
test/Basic/Swagger/ExamplesSchemaFilter.cs
Normal file
31
test/Basic/Swagger/ExamplesSchemaFilter.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user