OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.8k stars 6.58k forks source link

Unknown Java type created when using oneOf #8797

Open mutyasaisrikar opened 3 years ago

mutyasaisrikar commented 3 years ago

I am seeing an issue in Java for one of the fields. We have a field called ipAddress and the description in swagger is as below.

ipAddress: description: The location the content is trying to be played from type: string oneOf: [ {format: ipv4}, {format: ipv6} ]

Instead of creating it as a String, the openapi-generator-maven-plugin is creating it as OneOfAnyTypeAnyType

Also it is creating an import in API class for CollectionFormats.* which doesn't exist

ultraon commented 3 years ago

I fixed this issue by:

openApiGenerate {
  // ...
  globalProperties = [
    supportingFiles: ""
  ]
  // ...
}

and adding additional dependencies from auto-generated project gradle.build file:

dependencies {
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-scalars:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    implementation "io.reactivex.rxjava2:rxjava:$rx_java_version"
    implementation "io.swagger:swagger-annotations:$swagger_annotations_version"
    implementation ("org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"){
        exclude group:'org.apache.oltu.oauth2' , module: 'org.apache.oltu.oauth2.common'
    }
    implementation "io.gsonfire:gson-fire:$json_fire_version"
    implementation "joda-time:joda-time:$jodatime_version"
    implementation 'javax.annotation:javax.annotation-api:1.3.2'
}

But I don't like this solution. It might be a better solution to avoid generation supportingFiles into my build.gradle file.

HeedjyCompany commented 2 years ago

with openapi-generator-maven-plugin and this option

<generateSupportingFiles>false</generateSupportingFiles>

I still get an unknown import generated in the API class files

import x.y.z.CollectionFormats.*

ultraon commented 2 years ago

with openapi-generator-maven-plugin and this option

<generateSupportingFiles>false</generateSupportingFiles>

I still get an unknown import generated in the API class files

import x.y.z.CollectionFormats.*

As a workaround, you may create the empty class import x.y.z.CollectionFormats. I did this way.