Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem generating Java code with schema property "oneOf" #318

Open
jgarciasm opened this issue Apr 11, 2022 · 0 comments
Open

Problem generating Java code with schema property "oneOf" #318

jgarciasm opened this issue Apr 11, 2022 · 0 comments
Labels

Comments

@jgarciasm
Copy link

jgarciasm commented Apr 11, 2022

I have a problem trying to generate the code for an api that have "oneOf" property. The generated code give me the following exception when I try to call one endpoint.

To Reproduce:

1 - Generate the code for the following api: Rarible api
2 - Try to make a call to
xxx.api.ItemControllerApi.getAllItems(List.of(CustomEnum.ETHEREUM), null, 2, false, null, null);

Expected behavior:
Throw the following exception:
org.springframework.web.client.RestClientException: Error while extracting response for type [class xxx.model.Items] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Could not resolve subtype of [simple type, class xxx.model.MetaContent]: missing type id property 'type' (for POJO property 'content'); nested exception is com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve subtype of [simple type, class xxx.model.MetaContent]: missing type id property 'type' (for POJO property 'content')

Conclusion:
I am almost shure that the problem is related with the @JsonTypeInfo annotation because when I change the property value from type to another thing like "@type" the exception change and says ...missing type id property '@type'

@JsonTypeInfo(
  use = JsonTypeInfo.Id.NAME,
  include = JsonTypeInfo.As.PROPERTY,
  **property = "type"**)
@JsonSubTypes({
  @JsonSubTypes.Type(value = RaribleMcImageContent.class, name = "RaribleMcImageContent"),
  @JsonSubTypes.Type(value = RaribleMcVideoContent.class, name = "RaribleMcVideoContent"),
  @JsonSubTypes.Type(value = RaribleMcAudioContent.class, name = "RaribleMcAudioContent"),
  @JsonSubTypes.Type(value = RaribleMcModel3dContent.class, name = "RaribleMcModel3dContent")
})
public interface RaribleMcOneOfMetaContent {

}

Environment

Plugin version: 2.19.2
Swagger Codegen version: io.swagger.codegen.v3:swagger-codegen-cli:3.0.33
Gradle version: 7.4.1
Java version: Correto-17.0.2.8.1
OS: macOS Monterrey 12.3

@jgarciasm jgarciasm added the bug label Apr 11, 2022
@jgarciasm jgarciasm changed the title Problem generating Java code with json properties containing "@" in name Problem generating Java code with schema property "oneOf" Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant