我决定从 swagger 生成器迁移到 openapi 生成器。但是在生成期间我有一个错误。有趣的是,swagger 可以使用相同的 yaml 文件并生成没有错误的代码。
错误:
java.lang.RuntimeException: Could not process model 'DateTime'.Please make sure that your schema is correct!
at org.openapitools.codegen.DefaultGenerator.generateModels (DefaultGenerator.java:499)
at org.openapitools.codegen.DefaultGenerator.generate (DefaultGenerator.java:875)
at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:749)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
...//a lot of "at"
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
Caused by: java.nio.file.InvalidPathException: Illegal char <*> at index 125: C:\Users\imachuzhenko\IdeaProjects\smp\snef\target\generated-sources\openapi\src\main\java\generated\smf\model\org.joda.time.*.java
at sun.nio.fs.WindowsPathParser.normalize (WindowsPathParser.java:182)
at sun.nio.fs.WindowsPathParser.parse (WindowsPathParser.java:153)
at sun.nio.fs.WindowsPathParser.parse (WindowsPathParser.java:77)
at sun.nio.fs.WindowsPath.parse (WindowsPath.java:94)
at sun.nio.fs.WindowsFileSystem.getPath (WindowsFileSystem.java:255)
at java.nio.file.Paths.get (Paths.java:84)
at org.openapitools.codegen.DefaultGenerator.generateModels (DefaultGenerator.java:441)
at org.openapitools.codegen.DefaultGenerator.generate (DefaultGenerator.java:875)
...//a lot of "at"
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
在另一个 yaml 中定义的模型“DateTime”,即与生成的 yaml 文件位于同一目录中。
UPD。
在我的 pom.xml 文件中:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/5g_specs/TS29508_Nsmf_EventExposure.yaml</inputSpec>
<generatorName>java</generatorName>
<apiPackage>generated.smf.api</apiPackage>
<modelPackage>generated.smf.model</modelPackage>
<invokerPackage>generated.smf.invoker</invokerPackage>
<configOptions>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<artifactVersion>${project.version}</artifactVersion>
<library>okhttp-gson</library>
<skipValidateSpec>false</skipValidateSpec>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
UPD2
主要 yaml 中的参考:
EventNotification:
type: object
properties:
event:
$ref: '#/components/schemas/SmfEvent'
timeStamp:
$ref: 'TS29571_CommonData.yaml#/components/schemas/DateTime'
//and a lot of other properties
在 CommonData 中,它看起来像这样:
#
# COMMON SIMPLE DATA TYPES
#
...
DateTime:
format: date-time
type: string
我发现了如何解决这个问题。我没有使用最新的 5.1.0 版本的插件,而是使用 4.3.1 版本,我没有这个问题。5.x 版本不支持继承(我有 INFO 日志:
[deprecated] inheritance without use of 'discriminator.propertyName' has been deprecated in the 5.x release. Composed schema name: null. Title: null
但我需要使用最后一个版本。那么有没有另一种方法来解决这个问题呢?