【发布时间】:2020-01-19 18:52:21
【问题描述】:
我终于设法使用this tutorial 使用openapi-generator-maven-plugin 生成了一个Angular 客户端。
我不得不做出一些调整,例如使用不同的依赖项
<!-- Spring Docs (Swagger) -->
<!-- TODO After version upgrades check https://github.com/springdoc/springdoc-openapi/issues/133 -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-core</artifactId>
<version>1.1.49</version>
<exclusions>
<exclusion>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.1.49</version>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.44</version>
</dependency>
并且还必须添加更多参数,例如对于数据库驱动程序等:
<profile>
<id>angular</id>
<build>
<plugins>
<!-- Code Generation -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>reserve-tomcat-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>tomcat.http.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<!-- Spring Boot Maven plugin -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<addResources>true</addResources>
<arguments>
<!--suppress MavenModelInspection -->
<argument>--server.port=${tomcat.http.port}</argument>
<argument>--spring.profiles.active=angular</argument>
</arguments>
<environmentVariables>
<JDBC_DATABASE_URL>jdbc:postgresql://localhost/mydatabase</JDBC_DATABASE_URL>
<JDBC_DATABASE_USERNAME>postgres</JDBC_DATABASE_USERNAME>
<JDBC_DATABASE_PASSWORD>root</JDBC_DATABASE_PASSWORD>
</environmentVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.2</version>
<executions>
<execution>
<id>angular-client-code-generation</id>
<phase>integration-test</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!--suppress MavenModelInspection -->
<inputSpec>http://localhost:${tomcat.http.port}/v3/api-docs</inputSpec>
<output>${project.build.directory}/generated-sources/angular-client</output>
<generatorName>typescript-angular</generatorName>
<!--
Use this option to dump the configuration help for the specified generator
instead of generating sources:
<configHelp>true</configHelp>
-->
<configOptions>
<!--
Put generator-specific parameters here, e.g. for typescript-angular:
<apiModulePrefix>Backend</apiModulePrefix>
-->
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
但是现在,在生成代码后,我无法按照(生成的)README.md 中发布的说明进行操作:
@
建筑
安装所需的依赖项并构建打字稿 来源运行:
npm install npm run build出版
首先构建包然后运行
npm publish消费
导航到您的消费项目的文件夹并运行下一个 命令。
已发布:
npm install @ --save...
原因:没有 package.json,因此也没有可以首先执行的“构建”脚本。
因此,我想知道是否遗漏了什么或者我必须做些什么才能在我的 Angular 客户端中使用生成的代码。
【问题讨论】:
标签: angular spring-boot openapi-generator