我有一个 OpenAPI 文档,我想在 Swagger-UI 上生成随机 guid。目前,它正在生成一个未应用格式的“字符串”值。
{
"id": {
"type": "string",
"format": "guid"
}
}
这是我的代码:
app.UseSwaggerUi3(settings =>
{
settings.DocumentPath = $"/{pathBase}/api/specification.json";
});
app.UseOpenApi();
services.AddOpenApiDocument((configure, sp) =>
{
var config = sp.CreateScope().ServiceProvider
.GetRequiredService<IConfiguration>();
configure.PostProcess = d =>
{
d.Servers.Add(new NSwag.OpenApiServer { Url = $"/{config["SwaggerBasePath"]}" });
d.Servers.Add(new NSwag.OpenApiServer { Url = $"/" });
};
// Add the fluent validations schema processor
var fluentValidationSchemaProcessor =
sp.CreateScope().ServiceProvider.GetRequiredService<FluentValidationSchemaProcessor>();
configure.SchemaSettings.SchemaProcessors.Add(fluentValidationSchemaProcessor);
configure.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("JWT"));
});
如何每次生成随机guid?
没有为
guid
定义格式。
使用
uuid
{
"id": {
"type": "string",
"format": "uuid"
}
}