首页 > 解决方案 > 从 spring boot rest 控制器自动生成 typescript api

问题描述

我目前正在从 .json 定义文件中自动生成 typescript-angular 代码。我发现,当我从 swagger 访问/v2/api-docs页面时,swagger 会自动按名称标记我的 REST 控制器并将其写入定义文件。结果是,codegen 工具生成了多个很酷的服务文件。

kongchen在编译期间生成此 json的工具不会这样做。因此它只是写入所有端点,但没有以正确的形式对其进行标记,因此所有内容都放入同一个default.service.ts文件中。

有什么我错过的吗?所以最后我想要一个包含标签的swagger定义文件,这样就不会default.service.ts生成大的但是user.service.ts等等pet.service.ts

<plugin>
            <groupId>com.github.kongchen</groupId>
            <artifactId>swagger-maven-plugin</artifactId>
            <version>3.1.6</version>
            <configuration>
                <apiSources>
                    <apiSource>
                        <springmvc>true</springmvc>
                        <locations>
                            <location>com.project.main.Controller</location>
                        </locations>
                        <schemes>http</schemes>
                        <host>localhost:9999</host>
                        <basePath>/</basePath>
                        <info>
                            <title>Swagger Maven Plugin Spring Boot for cars</title>
                            <version>v1</version>
                            <description>Working sample of Spring Boot for cars annotations</description>
                            <termsOfService>
                                http://www.githubproeas.com
                            </termsOfService>
                            <contact>
                                <email>carsexample@email.com</email>
                                <name>Cars Example</name>
                                <url>http</url>
                            </contact>
                            <license>
                                <url>http://www.license.com</url>
                                <name>License name</name>
                            </license>
                        </info>
                        <outputFormats>json</outputFormats>
                        <swaggerDirectory>${basedir}/src/main/resources</swaggerDirectory>
                    </apiSource>
                </apiSources>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

标签: springtypescriptmavenswagger-codegen

解决方案


推荐阅读