Models are now typed as Object when properties of another Model
Description
This was asked in chat, and I've done some evaluation to determine what's going on. Models which are properties of other models are now considered Object
rather than the property type.
diff --git a/samples/client/petstore/kotlin/docs/Pet.md b/samples/client/petstore/kotlin/docs/Pet.md
index ec7756007..4b25ccb3e 100644
--- a/samples/client/petstore/kotlin/docs/Pet.md
+++ b/samples/client/petstore/kotlin/docs/Pet.md
@@ -5,7 +5,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **kotlin.Long** | | [optional]
-**category** | [**Category**](Category.md) | | [optional]
+**category** | [**kotlin.Any**](kotlin.Any.md) | A category for a pet | [optional]
**name** | **kotlin.String** | |
**photoUrls** | **kotlin.Array<kotlin.String>** | |
**tags** | [**kotlin.Array<Tag>**](Tag.md) | | [optional]
diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/Pet.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/Pet.kt
index 583dd3fb3..3ca832e7b 100644
--- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/Pet.kt
+++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/Pet.kt
@@ -11,14 +11,13 @@
*/
package org.openapitools.client.models
-import org.openapitools.client.models.Category
import org.openapitools.client.models.Tag
import com.squareup.moshi.Json
/**
* A pet for sale in the pet store
* @param id
- * @param category
+ * @param category A category for a pet
* @param name
* @param photoUrls
* @param tags
@@ -28,7 +27,8 @@ data class Pet (
val name: kotlin.String,
val photoUrls: kotlin.Array<kotlin.String>,
val id: kotlin.Long? = null,
- val category: Category? = null,
+ /* A category for a pet */
+ val category: kotlin.Any? = null,
val tags: kotlin.Array<Tag>? = null,
/* pet status in the store */
val status: Pet.Status? = null
Apparently, our petstore example for many generated samples only nest models once (Category
under Pet#category
). This bug appears to happen for any nested models. Nested enums and arrays of types are unaffected.
openapi-generator version
master (752b36e6)
OpenAPI declaration file content or url
n/a
Command line used for generation
Any generator under ./bin
with nested models
Steps to reproduce
- pull current master branch (752b36e6)
- execute
mvn clean package install
- execute
./bin/kotlin-client-petstore.sh
- execute
cat samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/Pet.kt
Notice that category is now kotlin.Any?
rather than Category
as it was previously.
Related issues/PRs
- Introduced via #45
Suggest a fix/enhancement
Nothing substantial to suggest. Maybe copying non-empty properties to the new schema rather than replacing the reference?
@jmini you commented in the PR that the fix is temporary. However, I consider the issue a significant one.
It looks like this block is the bug:
+ Schema prop = entry.getValue();
+ if (allDefinitions != null && prop != null && StringUtils.isNotEmpty(prop.get$ref())) {
+ String refName = ModelUtils.getSimpleRef(prop.get$ref());
+ prop = allDefinitions.get(refName);
+ }
I haven't stepped through the code to verify, but it seems to me that this would be falling back to Object
where it shouldn't be. I saw that you opened a bug with swagger-parser for the json-schema properties that don't get exposed as expected. I think that parser bug is unrelated to this bug.
For reference, I tracked this down via git bisect using:
Would you mind giving this a quick look? I had planned to get into a fix, but I wasted a big of time with my evaluation script (running kotlin-client generator, then checking kotlin-server output produced only HEAD as the bad commit).