Skip to content

quarkus-smallrye-openapi: Generated OpenAPI schema does not respect @JsonFormat(shape = JsonFormat.Shape.ARRAY) #35444

Open

Description

Describe the bug

The OpenAPI schema generated in the directory specified by the quarkus.smallrye-openapi.store-schema-directory property does not respect @JsonFormat(shape = JsonFormat.Shape.ARRAY).
For instance, given the class below:

package org.acme;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import java.util.Objects;

@JsonFormat(shape = JsonFormat.Shape.ARRAY)
@JsonPropertyOrder({"from", "to", "message"})
public class GreetingItem {
    final String from;
    final String to;
    final String message;

    public GreetingItem(@JsonProperty("from") String from,
                        @JsonProperty("to") String to,
                        @JsonProperty("message") String message) {
        this.from = from;
        this.to = to;
        this.message = message;
    }

    public String getFrom() {
        return from;
    }

    public String getTo() {
        return to;
    }

    public String getMessage() {
        return message;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        GreetingItem that = (GreetingItem) o;
        return Objects.equals(from, that.from) && Objects.equals(to, that.to) && Objects.equals(message, that.message);
    }

    @Override
    public int hashCode() {
        return Objects.hash(from, to, message);
    }

    @Override
    public String toString() {
        return "GreetingItem{" +
                "from='" + from + '\'' +
                ", to='" + to + '\'' +
                ", message='" + message + '\'' +
                '}';
    }
}

and the endpoint below:

package org.acme;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/hello")
public class GreetingResource {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public GreetingItem hello() {
        return new GreetingItem("RESTEasy Reactive",
                "You",
                "Hello!");
    }
}

The OpenAPI schema should define GreetingItem as an array of type string containing exactly 3 items. Instead, it define it as a JSON object containing properties from, to and message.

Expected behavior

For the example above, this YAML is generated in the directory specified by quarkus.smallrye-openapi.store-schema-directory:

---
openapi: 3.0.3
info:
  title: getting-started API
  version: 1.0.0-SNAPSHOT
servers:
- url: http://localhost:8080
  description: Auto generated value
- url: http://0.0.0.0:8080
  description: Auto generated value
paths:
  /hello:
    get:
      tags:
      - Greeting Resource
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GreetingItem'
components:
  schemas:
    GreetingItem:
      type: array
      items:
        type: string
      minItems: 3
      maxItems: 3
  securitySchemes:
    SecurityScheme:
      type: http
      description: Authentication
      scheme: basic

Actual behavior

For the example above, this YAML is generated in the directory specified by quarkus.smallrye-openapi.store-schema-directory:

---
openapi: 3.0.3
info:
  title: getting-started API
  version: 1.0.0-SNAPSHOT
servers:
- url: http://localhost:8080
  description: Auto generated value
- url: http://0.0.0.0:8080
  description: Auto generated value
paths:
  /hello:
    get:
      tags:
      - Greeting Resource
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GreetingItem'
components:
  schemas:
    GreetingItem:
      type: object
      properties:
        from:
          type: string
        to:
          type: string
        message:
          type: string
  securitySchemes:
    SecurityScheme:
      type: http
      description: Authentication
      scheme: basic

How to Reproduce?

Reproducer: https://github.com/Christopher-Chianelli/issue-reproducer/tree/quarkus-openapi-schema-json-array

Steps to reproduce:

  1. cd getting-started

  2. mvn clean package

  3. cat target/openapi-schema/openapi.yaml

Output of uname -a or ver

Linux babbage 6.4.11-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 16 17:42:12 UTC 2023 x86_64 GNU/Linux

Output of java -version

openjdk 17.0.8 2023-07-18

GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.2.4.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.6 (Red Hat 3.8.6-4)

Additional information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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