Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 是否可以按名称空间动态创建招摇过市规格?_Asp.net Core_Swagger - Fatal编程技术网

Asp.net core 是否可以按名称空间动态创建招摇过市规格?

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

我想在我的mvc应用程序中创建按名称空间分组的招摇过市规范

例如,如果我有以下api控制器:

- 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。但我希望它能有所帮助。如果你觉得不行,我可以把它删除。类名看起来很相似,所以我现在试着翻译它。我说别管了。