Skip to content

Support OpenAPI specs split across multiple files (cross-file $ref resolution) #499

Open

Description

@mathecruz

Motivation

Consumers of this codegen (e.g. quarkus-openapi-generator) currently have to pre-resolve
multi-file OpenAPI specs themselves before handing a single JSON document to this library,
because OpenApi2JaxRs / DocumentPreProcessor only resolve $refs that point inside the
same document (#/components/schemas/...). There is no support for $refs that point to
another file, e.g.:

# module1.yaml
paths:
  /pets:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: './common-spec.yaml#/components/schemas/Pet'

Today, quarkus-openapi-generator works around this by parsing the entry spec with
swagger-parser (setResolve(true), setResolveFully(true), setResolveCombinators(true)),
flattening every external $ref into a single resolved document, and only then handing the
JSON to this project. That means every consumer of this library has to reimplement the same
workaround, using a completely different OpenAPI object model (swagger-core) than the one this
project uses internally (io.apitomy.datamodels). It was also the root cause of a separate bug
where OpenAPI 3.1 schema types were silently dropped during that round-trip (see companion
issue: type/types lost for 3.1 — link once filed).

Proposal

Teach this project's own document loading / DocumentPreProcessor pipeline to resolve relative
$refs against sibling files on disk (and, ideally, combinators like allOf/oneOf/anyOf
that span files), using the existing io.apitomy.datamodels model, so consumers can pass a
multi-file spec's entry document directly without a separate pre-resolution pass.

Scope / open questions

  • Resolve $ref to other local files (relative paths), not just same-document refs.
  • Decide how deep the resolution needs to go (just schemas, or also parameters/responses/
    requestBodies that live in other files).
  • Out of scope for this issue: remote (http(s)://) $refs, unless trivial to support.

Context

Activity

  1. EricWittmann commented on Oct 29, 2026

    @EricWittmann
    Contributor

    Suggestion: use the dereferencing logic to dereference/normalize the openapi spec into a single document before processing in apitomy-codegen.

    Take a look at this:

  2. added
    type/enhancement
    area/jaxrs
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/jaxrstype/enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions