Asp.net core 是否可以按名称空间动态创建招摇过市规格?
我想在我的mvc应用程序中创建按名称空间分组的招摇过市规范 例如,如果我有以下api控制器:Asp.net core 是否可以按名称空间动态创建招摇过市规格?,asp.net-core,swagger,Asp.net Core,Swagger,我想在我的mvc应用程序中创建按名称空间分组的招摇过市规范 例如,如果我有以下api控制器: - Portal.Example1.Sub1 - Portal.Example1.Sub2 - Portal.Example2.Section2 - Portal.Example2.Section4 - Portal.Example3.Something4 - Portal.Example3.Whatever69 我希望output swagger ui页面为Example1创建一个规范,其中包含Su
- Portal.Example1.Sub1
- Portal.Example1.Sub2
- Portal.Example2.Section2
- Portal.Example2.Section4
- Portal.Example3.Something4
- Portal.Example3.Whatever69
我希望output swagger ui页面为Example1
创建一个规范,其中包含Sub1
和Sub2
中的所有操作,等等
目前,我的代码设置为:
在启动中:配置服务:
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new Info { Title = "Portal API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.EnableAnnotations();
});
在启动中:配置
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Portal API V1");
options.IndexStream = () => Assembly.GetExecutingAssembly().GetManifestResourceStream("Portal.Web.wwwroot.swagger.ui.index.html");
options.InjectBaseUrl(""http://localhost:62114/");
}); //URL: /swagger
我想我已经用spring创建了这样的类:
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@Api(value = "categoryA", description = "categoryA Managent")
@RestController
@RequestMapping("/api/categoryA")
public class CategoryA {
...
}
当我查看代码时,它与一个包一起工作。如果您遇到问题,您可能需要以如下方式进行更改:
@SpringBootApplication
@EnableSwagger2
@ComponentScan(basePackages = {"Portal.controller", "Portal.AllExamples"})
public class Application {
@Value("${info.app.version:unknown}") String version;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage(Portal.AllExamples.class.getPackage().getName()))
.paths(PathSelectors.regex("/.*")).build().apiInfo(apiEndPointsInfo());
}
public ApiInfo apiEndPointsInfo() {
return new ApiInfoBuilder().title("My REST API").description("bla bla bla.")
.contact(new Contact("yourcorp", "yoururl", "you@mail"))
.license("free for all license").licenseUrl("https://free.beer.org").version(version)
.build();
}
…这看起来像是有棱角的,我试图在asp.net核心(c#)和常规html/jsno中实现这一点,它是java。但我希望它能有所帮助。如果你觉得不行,我可以把它删除。类名看起来很相似,所以我现在试着翻译它。我说别管了。