Unable to generate java client code from a version 2 OpenApi spec
Created by: jeff9finger
Description
I am trying to generate a java client from an Open API version 2 spec. But the generator does not validate the spec.
openapi-generator version
3.0.1, 3.0.2-SNAPSHOT
OpenAPI declaration file content or url
swagger: "2.0"
info:
version: "2"
title: "TRACT Billing API"
basePath: "/billing/2"
consumes:
- "application/json"
produces:
- "application/json"
security:
- api_key_header: []
- defined_bearer_token: []
paths:
/actions:
get:
tags:
- "Action"
summary: "Get actions"
operationId: "queryActions"
produces:
- "application/json"
parameters:
- name: "id"
in: "query"
description: "The internal ID of the object."
required: false
type: "string"
responses:
200:
description: "Success"
schema:
type: "array"
items:
$ref: "#/definitions/Action"
headers:
ETag:
type: "string"
description: "The standard ETag HTTP header."
X-total-count:
type: "integer"
format: "int64"
description: "The total results for the particular query. Used to drive\
\ paging requests."
X-element-count:
type: "integer"
format: "int64"
description: "The number of elements returned in the current request.\
\ Used to drive paging requests."
X-total-pages:
type: "integer"
format: "int64"
description: "The total number of pages that can be requested. Used\
\ to drive paging requests."
400:
description: "Bad request."
schema:
$ref: "#/definitions/ApiError"
default:
description: "Unknown error."
schema:
$ref: "#/definitions/ApiError"
security:
- api_key_header: []
- defined_bearer_token: []
x-swagger-router-controller: "ActionsController"
definitions:
Entity:
type: "object"
properties:
id:
type: "string"
example: "1438752"
description: "(unique_key) The ID of the entity."
readOnly: true
title: "Entity"
description: "A base object for all API entities."
Action:
title: "Action"
allOf:
- $ref: "#/definitions/Entity"
- type: "object"
required:
- "action_type"
discriminator: "action_type"
properties:
name:
type: "string"
description: "The name of the action."
readOnly: true
enabled:
type: "boolean"
description: "Specifies whether the action is enabled."
readOnly: true
friendly_name:
type: "string"
description: "The optional additional name of the action."
readOnly: true
supports_approval:
type: "boolean"
description: "Specifies whether the action supports approval."
readOnly: true
action_type:
$ref: "#/definitions/ActionType"
ActionType:
type: "string"
title: "ActionType"
description: "Indicates the type of action that occurs."
enum:
- "agreement"
- "agreement-service"
- "bill-cycle-run"
- "bill-batch-run"
- "billing-account"
- "counter"
- "credit-adjustment"
- "disbursement"
- "invoice"
- "payment"
- "product-sale"
- "remote-prepaid-register"
- "sales-order"
- "service"
- "service-cfv"
- "system-notification"
- "usage-rule"
x-swagger-router-model: "ActionTypeDto"
Command line used for generation
Steps to reproduce
java -jar openapi-generator-cli.jar generate --generator-name java --library jersey2 --input-spec test
.yaml --output src --verbose
Output:
[main] INFO o.o.c.config.CodegenConfigurator -
VERBOSE MODE: ON. Additional debug options are injected
- [debugSwagger] prints the openapi specification as interpreted by the codegen
- [debugModels] prints models passed to the template engine
- [debugOperations] prints operations passed to the template engine
- [debugSupportingFiles] prints additional data passed to the template engine
Exception in thread "main" java.lang.IllegalArgumentException: Cannot construct instance of `io.swagger.v3.oas.models.media.Discriminator` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('action_type')
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: io.swagger.v3.oas.models.media.ObjectSchema["discriminator"]) (through reference chain: io.swagger.v3.oas.models.media.ComposedSchema["allOf"]->java.util.ArrayList[1])
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:3738)
at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:3656)
at io.swagger.v3.parser.converter.SwaggerConverter.convert(SwaggerConverter.java:1062)
at io.swagger.v3.parser.converter.SwaggerConverter.convert(SwaggerConverter.java:215)
at io.swagger.v3.parser.converter.SwaggerConverter.readLocation(SwaggerConverter.java:93)
at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:19)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:516)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:314)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:58)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Cannot construct instance of `io.swagger.v3.oas.models.media.Discriminator` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('action_type')
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: io.swagger.v3.oas.models.media.ObjectSchema["discriminator"]) (through reference chain: io.swagger.v3.oas.models.media.ComposedSchema["allOf"]->java.util.ArrayList[1])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:391)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:363)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:302)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:245)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:127)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:3733)
... 8 more
Caused by: java.lang.IllegalArgumentException: Cannot construct instance of `io.swagger.v3.oas.models.media.Discriminator` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('action_type')
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: io.swagger.v3.oas.models.media.ObjectSchema["discriminator"])
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:3738)
at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:3656)
at io.swagger.v3.core.util.ModelDeserializer.deserializeObjectSchema(ModelDeserializer.java:106)
at io.swagger.v3.core.util.ModelDeserializer.deserialize(ModelDeserializer.java:76)
at io.swagger.v3.core.util.ModelDeserializer.deserialize(ModelDeserializer.java:28)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:286)
... 14 more
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `io.swagger.v3.oas.models.media.Discriminator` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('action_type')
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: io.swagger.v3.oas.models.media.ObjectSchema["discriminator"])
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1342)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1031)
at com.fasterxml.jackson.databind.deser.ValueInstantiator._createFromStringFallbacks(ValueInstantiator.java:371)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:323)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1366)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:171)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:161)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:127)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:3733)
... 19 more