payara / Payara

Payara Server is an open source middleware platform that supports reliable and secure deployments of Java EE (Jakarta EE) and MicroProfile applications in any environment: on premise, in the cloud or hybrid.
http://www.payara.fish
Other
884 stars 307 forks source link

OpenAPI ApplicationProcessor does not support parsing request/response classes using generics /CUSTCOM-30 #4148

Closed haraldatbmw closed 4 years ago

haraldatbmw commented 5 years ago

Description

The OpenAPI parser (fish.payara.microprofile.openapi.impl.processor.ApplicationProcessor) does not support parsing request/response classes using generics. Therefor the generated OpenAPI document is not complete (see current vs. expected outcome below).

@Path("zoo")
public class ZooResource {
    @Schema(description = "JSON wrapper for a list of animals")
    public static class JsonAnimalList extends JsonData<JsonItems<Animal>> {
        public JsonAnimalList(List<Animal> items, int totalItems) {
            super(new JsonItems<Animal>(items, totalItems));
        }
    }

    @GET
    public JsonAnimalList loadAnimals() {
        List<Animal> animals = new ArrayList<>();
        animals.add(new Animal("Leo the tiger", 7));
        animals.add(new Animal("Joe the wolf", 11));

        return new JsonAnimalList(animals, animals.size());
    }
}

JSON response of http://localhost:8080/openapi-showcase/resources/zoo

{
    "data":
    {
        "items":
        [
            {"age":7,"name":"Leo the tiger"},
            {"age":11,"name":"Joe the wolf"}
        ],
        "totalItems":2
    }
}

Generated OpenAPI document

openapi: 3.0.0
info:
  title: Deployed Resources
  version: 1.0.0
servers:
- url: http://LMUC795407.europe.bmw.corp:8080/openapi-showcase
  description: Default Server.
- url: https://LMUC795407.europe.bmw.corp:8181/openapi-showcase
  description: Default Server.
paths:
  /resources/zoo:
    get:
      operationId: loadAnimals
      responses:
        default:
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/JsonAnimalList'
          description: Default Response.
components:
  schemas:
    JsonAnimalList:
      description: JSON wrapper for a list of animals
      allOf:
      - $ref: '#/components/schemas/JsonData'
    JsonData:
      type: object
      properties:
        data:
          type: object

Expected Outcome

openapi: 3.0.0
info:
  title: Deployed Resources
  version: 1.0.0
paths:
  /resources/zoo:
    get:
      responses:
        200:
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/JsonAnimalList'
components:
  schemas:
    JsonAnimalList:
      description: JSON wrapper for a list of animals
      type: object
      properties:
        data:
          type: object
          properties:
            items:
              type: array
              items:
                type: object
                properties:
                  age:
                    format: int32
                    type: integer
                  name:
                    type: string
            totalItems:
              format: int32
              type: integer

Steps to reproduce

Build and deploy the project https://github.com/haraldatbmw/openapi-showcase on the payara and open the URL http://localhost:8080/openapi

Hint

The smallrye-open-api implementation does the job correct.

Environment

rdebusscher commented 5 years ago

Hi @haraldatbmw,

Thank you for this report and I have created the internal ticket PAYARA-4074 for the engineering team to fix this issue.

Regards Rudy

thschoen commented 5 years ago

+1

jbee commented 5 years ago

It might be that the title is somewhat misleading associating the problem with generics when it might be that we don't support inheritance in the way it is used or the simple fact that lists are treated like arrays would or recognised as such beyond the obvious types. Same might be true for map types. Just something to think about when working on this.

haraldatbmw commented 4 years ago

@rdebusscher Do you have any news on your internal ticket PAYARA-4074?

rdebusscher commented 4 years ago

@haraldatbmw Development is not started yet.

rdebusscher commented 4 years ago

Tracked now as CUSTCOM-30