简体   繁体   中英

How to include custom statements/directive in C# code generated by NSwag?

I generated C# code from a Swagger definition and was wondering if there is a configuration parameter to automatically include using statements in the generated files. I found this link https://github.com/RicoSuter/NSwag/wiki/NSwag-Configuration-Document with config-parameters but none of these seems to make the trick. To be more clear, my file at the moment looks like this at the top:

在此输入图像描述

I would like the autogenerated file to include using statements like this:

在此输入图像描述

Any help or tips are very appretiated.

In your NSwag configuration, you can set:

"openApiToCSharpClient": {
  ...
  "additionalNamespaceUsages": [
    "RDT.Api.DomainModels"
  ],
  ...
  "namespace": "RDT.Api.Repository",
  ...
}

Alternately, NSwagStudio includes an option 'Additional Namespace Usages'.

NSwagStudio配置

To keep the settings, you can save your .nswag file for future use

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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