Skip to content

[BUG] ApiException does not contains Error object #4777

@gigaga

Description

@gigaga
Description

After generating Java client, in case of error, ApiException is thrown but it doesn't contains the Error object defined in specs file.

openapi-generator version

release : 4.2.2

OpenAPI declaration file content or url

Below my spec file where Error object should be returned in case http status code is not 200.

openapi: "3.0.0"
info:
  version: 1.0.0
  title: petstore
  description: |
    This is the specification of Petstore with the following resources:

    - Pet
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
    
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Pets:
      type: array
      items:
        $ref: "#/components/schemas/Pet"
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
Command line used for generation
./gradlew clean openApiGenerate

with the following build.gradle file:

plugins {
  id "org.openapi.generator" version "4.2.2"
  id 'java'
}

repositories {
  mavenCentral()
}


dependencies {
    compile 'com.squareup.okhttp3:okhttp:4.2.2'
    compile 'com.squareup.okhttp3:logging-interceptor:4.2.2'
    compile 'org.threeten:threetenbp:1.4.0'
    compile 'com.google.code.gson:gson:2.8.6'
    compile 'io.gsonfire:gson-fire:1.8.3'
    compile 'io.swagger:swagger-annotations:1.6.0'
    compile 'com.google.code.findbugs:jsr305:3.0.2'
}

openApiGenerate {
    generatorName = "java"   // Language target
    inputSpec = "$rootDir/petstore-one.yaml".toString() // Path to specifications file
}
Steps to reproduce

When I implement the client use like this, I'd like to work with Error object from ApiException but just responseBody is returned but it is not deserialized :(

                try {
			api.listPets(transaction);
		} catch (ApiException ex) {
			// How get Error object?
		}

I tried for several language (Ruby, JS, Python), it seems that there is the same issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions