quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.36k stars 2.56k forks source link

OpenAPI does not support including references from other files #29804

Open gregopet opened 1 year ago

gregopet commented 1 year ago

Describe the bug

We are heavy users of OpenAPI's references, specifically, we split paths and model definitions into separate files (see sample below). This works for generating the code, but fails for publishing: the $ref is simply output, with no substitution, and trying to fetch the references individually fails as well (404 is returned).

A simple sample would look like this:

# openapi.yml
openapi: 3.0.3
info:
  title: rest-kotlin-quickstart API
  version: 1.0.0-SNAPSHOT
paths:
  /hello:
    get:
      operationId: hello
      tags:
        - Greeting
      responses:
        "200":
          description: OK
          content:
            text/plain:
              schema:
                $ref: './Hello.yaml'

### Hello.yaml
type: object
properties:
  name:
    type: string

Expected behavior

I would either expect the definitions to be available at their respective URLs or the spec to include these references in the resulting schema.

Actual behavior

The $ref elements come through verbatim and their targets are not available.

How to Reproduce?

Install the OpenAPI support as per tutorial and add the two OpenAPI files I listed above. Start Quarkus and open http://localhost:8080/q/openapi?format=json

Output of uname -a or ver

Linux *** 6.0.10-arch2-1 #1 SMP PREEMPT_DYNAMIC Sat, 26 Nov 2022 16:51:18 +0000 x86_64 GNU/Linux

Output of java -version

openjdk version "17.0.1" 2021-10-19 OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12) OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (build 17.0.1+12, mixed mode, sharing)

GraalVM version (if different from Java)

not using Graal

Quarkus version or git rev

2.14.2.Final

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

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)

Additional information

openapi-generator-maven-plugin plugin version 6.2.1

geoand commented 1 year ago

cc @MikeEdgar

gregopet commented 7 months ago

We've come up with a workaround: we use openapi generator to transpile the schema into a simple JSON which we then let Quarkus serve. For example:

<plugin>
  <groupId>org.openapitools</groupId>
  <artifactId>openapi-generator-maven-plugin</artifactId>
  <executions>

    <execution>
      <id>openapi-export-version</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <generatorName>openapi</generatorName>
        <inputSpec>${project.basedir}/src/main/resources/api/own/openapi.yaml</inputSpec>
        <output>target/classes/META-INF</output>
        <configOptions>
          <outputFileName>openapi.json</outputFileName>
        </configOptions>
      </configuration>
    </execution>

    <execution>
      <id>openapi</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>${project.basedir}/src/main/resources/api/own/openapi.yaml</inputSpec>
        <output>target/generated-sources/openapi</output>
        <apiPackage>org.acme.api</apiPackage>
        <modelPackage>org.acme.model</modelPackage>
      </configuration>
    </execution>

  </executions>
</plugin>