简体   繁体   English

如何从openapi 2.0生成的对象命名空间中删除破折号

[英]How to remove dashes from object namespace, generated by openapi 2.0

I use Swashbuckle.AspNetCore (v4.0.1) to generate swagger.json file in asp .net core. 我使用Swashbuckle.AspNetCore (v4.0.1)在asp .net核心中生成swagger.json文件。 After the import in Azure API Management we see the following types that we don't expect: SwaggerGenerationSample-Models-EmployeeArray and SwaggerGenerationSample-Models-EmployeeArray-1 etc. . 在Azure API Management中导入后,我们会看到以下不期望的类型: SwaggerGenerationSample-Models-EmployeeArraySwaggerGenerationSample-Models-EmployeeArray-1等。

I expect to have dots instead of dashes SwaggerGenerationSample.Models.EmployeeArray . 我希望有点而不是破折号SwaggerGenerationSample.Models.EmployeeArray

I tried to use 我试着用

CustomSchemaIds(t => t.Name), instead of CustomSchemaIds(t => t.FullName)

but don't work due to some duplicated object names (Request.Employee and Response.Employee). 但由于某些重复的对象名称(Request.Employee and Response.Employee).而无法工作(Request.Employee and Response.Employee).

I currently have the following configuration in AspNetCore. 我目前在AspNetCore中有以下配置。

services.AddSwaggerGen(config => {
   config.DescribeAllEnumsAsStrings();
   config.CustomSchemaIds(type => type.FullName);
   config.SwaggerDoc("v1", new Info { Title = "SampleAPI", Version = "v1" });
   config.MapType<decimal>(() => new Schema { Type = "number", Format = "double" });
   config.MapType<decimal?>(() => new Schema { Type = "number", Format = "double" });
 });

I believe , this is because of the recent changes how Open API import and export works in APIM. 我相信,这是因为Open API导入和导出在APIM中的最新变化。 You can find the semantics here as it aligns with it. 您可以在此处找到语义因为它与之对齐。

Here is the normalization rule for the same: 以下是相同的规范化规则:

Normalization rules for operationId operationId的规范化规则

  • Convert to lower case. 转换为小写。
  • Replace each sequence of non-alphanumeric characters with a single dash, eg GET-/foo/{bar}?buzz={1} will be transformed into get-foo-bar-buzz-1- . 用一个短划线替换每个非字母数字字符序列,例如GET-/foo/{bar}?buzz={1}将转换为get-foo-bar-buzz-1-
  • Trim dashes on both sides, eg get-foo-bar- will become get-foo-bar 修剪双方的破折号,例如get-foo-bar-将成为get-foo-bar
  • Truncate to fit 76 characters, four characters less than maximum limit for a resource name. 截断以适合76个字符,小于资源名称的最大限制的四个字符。
  • Use remaining four characters for a deduplication suffix, if necessary, in the form of -1, -2, …, -999. 如有必要,请使用剩余的四个字符作为重复数据删除后缀,格式为-1,-2,...,-999。

You can read more about it here : 你可以在这里阅读更多相关信息:

https://blogs.msdn.microsoft.com/apimanagement/2018/04/11/important-changes-to-openapi-import-and-export/ https://blogs.msdn.microsoft.com/apimanagement/2018/04/11/important-changes-to-openapi-import-and-export/

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM