-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Labels
Description
Description
openapi-generator-maven-plugin release version 5.1.0
A Java client, generated with openapi-generator-maven-plugin will throw a com.google.gson.JsonSyntaxException during JSON deserialization of a server response:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 44 path $[0].value
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.Gson.fromJson(Gson.java:932)
at com.google.gson.Gson.fromJson(Gson.java:897)
at com.google.gson.Gson.fromJson(Gson.java:846)
Server response JSON:
[{"value":1000.0}]
Minimal example spec:
openapi: 3.0.0
info:
description: Minimal Spec
version: 1.0.0
title: Test
servers:
- url: test
description: Service name
paths:
"/read":
post:
operationId: readList
description: Read list of values
responses:
'200':
"$ref": "#/components/responses/ValueList"
components:
responses:
ValueList:
description: List of value list objects
content:
application/json:
schema:
"$ref": "#/components/schemas/ValueList"
schemas:
ValueList:
description: Array of value objects
type: array
items:
"$ref": "#/components/schemas/ValueObject"
ValueObject:
type: object
description: A value object
required:
- value
properties:
value:
"$ref": "#/components/schemas/Value"
Value:
description: Value datatype
oneOf:
- "$ref": "#/components/schemas/Scalar"
- "$ref": "#/components/schemas/Array"
Scalar:
description: Scalar datatype
oneOf:
- type: string
maxLength: 1089
- type: number
- type: boolean
Array:
type: array
minItems: 1
items:
"$ref": "#/components/schemas/Scalar"
Because of the exception further processing is interrupted.
openapi-generator version
openapi-generator-maven-plugin release version 5.1.0
Generation Details
Following maven pom.xml is used to generate the Java Client:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>src-gen</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>5.1.0</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>http://.../api.yaml</inputSpec>
<generatorName>java</generatorName>
<output>${project.basedir}</output>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<packageName>at.internal.test</packageName>
<apiPackage>at.internal.test</apiPackage>
<modelPackage>at.internal.test.model</modelPackage>
<invokerPackage>at.internal.test.invoker</invokerPackage>
<withXml>false</withXml>
<configOptions>
<sourceFolder>src-gen</sourceFolder>
</configOptions>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Steps to reproduce
- Generate Java client and server with example spec
- Generate client request / server response
- Server should response with JSON
- Exception will be thrown on client
Related issues/PRs
--
Suggest a fix
--
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists? -> Not possible -> openapi-generator-maven-plugin generates invalid Java code when using "oneOf:" property #12556
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
PVIII