Igor_M
Igor_M

Reputation: 338

openAPI generator error: Could not process model 'DateTime'. Please make sure that your schema is correct

I've decided to migrate from swagger generator to openapi generator. But during generation I have an error. Interesting that swagger works with the same yaml file and generates code without errors.

Error:

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)

The model "DateTime" defined in another yaml, that is in the same directory with generated yaml file.

UPD.

In my pom.xml file:

<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

Reference in main yaml:

EventNotification:
  type: object
  properties:
    event:
      $ref: '#/components/schemas/SmfEvent'
    timeStamp:
      $ref: 'TS29571_CommonData.yaml#/components/schemas/DateTime'
    //and a lot of other properties

And in CommonData it looks like this:

#
# COMMON SIMPLE DATA TYPES
#
...
    DateTime:
      format: date-time
      type: string

I founded out how to pass this problem. Instead of using newest 5.1.0 version of plugin, I use 4.3.1 version and I don't have this problem. 5.x versions do not support inheritance (I had INFO log:

[deprecated] inheritance without use of 'discriminator.propertyName' has been deprecated in the 5.x release. Composed schema name: null. Title: null

But I need to use the last version. So is there another way to solve the problem?

Upvotes: 2

Views: 7656

Answers (2)

kyrie_eleison
kyrie_eleison

Reputation: 46

Try changing the name of component "DateTime" to something else. I think it's naming conflict while generation or smth. At least, it's solved my problem with exact same trace.

Just in case:

<configOptions>
        <dateLibrary>java8-localdatetime</dateLibrary>
        <interfaceOnly>true</interfaceOnly>
</configOptions>

Upvotes: 1

Sanchit Kumar
Sanchit Kumar

Reputation: 1

I faced a similar issue. To fix this I added dateLibrary as joda in the configOptions. Also added the dependency of joda-time.

<configOptions>
    <dateLibrary>joda</dateLibrary>
    <java8>true</java8>
    <interfaceOnly>false</interfaceOnly>
    <delegatePattern>false</delegatePattern>
    <sourceFolder>./</sourceFolder>
</configOptions>

Upvotes: 0

Related Questions