Discriminator is not included if objects are used in a list during tests #56

Closed
opened 2021-03-05 22:19:16 +01:00 by BrandonSchmitt · 0 comments
BrandonSchmitt commented 2021-03-05 22:19:16 +01:00 (Migrated from github.com)

I have an operation accepting a list of objects which use inheritance in the request body. When executing a test, I get the following error:

io.micronaut.http.client.exceptions.HttpClientResponseException: 
Error decoding HTTP response body: Error decoding stream for type [interface java.util.List]: Missing type id when trying to resolve subtype of [simple type, ModelVO]: missing type id property 'type'
 at [Source: (byte[])"[{"enabled":true, ...}]"; line: 1, column: 168] (through reference chain: java.util.ArrayList[0])
	at io.micronaut.http.client.netty.DefaultHttpClient$12.channelRead0(DefaultHttpClient.java:2186)
...

Caused by: io.micronaut.http.codec.CodecException: Error decoding stream for type [interface java.util.List]: Missing type id when trying to resolve subtype of [simple type, class ModelVO]: missing type id property 'type'
 at [Source: (byte[])"[{"enabled":true, ...}]"; line: 1, column: 168] (through reference chain: java.util.ArrayList[0])
	at io.micronaut.jackson.codec.JacksonMediaTypeCodec.decode(JacksonMediaTypeCodec.java:194)

...

Caused by: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class ModelVO]: missing type id property 'type'
 at [Source: (byte[])"[{"enabled":true, ...}]"; line: 1, column: 168] (through reference chain: java.util.ArrayList[0])
	at com.fasterxml.jackson.databind.exc.InvalidTypeIdException.from(InvalidTypeIdException.java:43)

If I change the operation to just take one object instead of a list of those objects it works perfectly.

After debugging for a while I assume it's just the test client not serializing the discriminator property as expected. I have created a test case covering this issue: github.com/BrandonSchmitt/micronaut-openapi-codegen@04b7cc6a4e

I have an operation accepting a list of objects which use inheritance in the request body. When executing a test, I get the following error: ``` io.micronaut.http.client.exceptions.HttpClientResponseException: Error decoding HTTP response body: Error decoding stream for type [interface java.util.List]: Missing type id when trying to resolve subtype of [simple type, ModelVO]: missing type id property 'type' at [Source: (byte[])"[{"enabled":true, ...}]"; line: 1, column: 168] (through reference chain: java.util.ArrayList[0]) at io.micronaut.http.client.netty.DefaultHttpClient$12.channelRead0(DefaultHttpClient.java:2186) ... Caused by: io.micronaut.http.codec.CodecException: Error decoding stream for type [interface java.util.List]: Missing type id when trying to resolve subtype of [simple type, class ModelVO]: missing type id property 'type' at [Source: (byte[])"[{"enabled":true, ...}]"; line: 1, column: 168] (through reference chain: java.util.ArrayList[0]) at io.micronaut.jackson.codec.JacksonMediaTypeCodec.decode(JacksonMediaTypeCodec.java:194) ... Caused by: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class ModelVO]: missing type id property 'type' at [Source: (byte[])"[{"enabled":true, ...}]"; line: 1, column: 168] (through reference chain: java.util.ArrayList[0]) at com.fasterxml.jackson.databind.exc.InvalidTypeIdException.from(InvalidTypeIdException.java:43) ``` If I change the operation to just take one object instead of a list of those objects it works perfectly. After debugging for a while I assume it's just the test client not serializing the discriminator property as expected. I have created a test case covering this issue: https://github.com/BrandonSchmitt/micronaut-openapi-codegen/commit/04b7cc6a4ed1b7415f40155cf97796bac5ed4422
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
kokuwaio/micronaut-openapi-codegen#56
No description provided.