OpenAPITools / OpenAPITools/openapi-generator

[BUG][Openapi] generator works on original YAML files, but fails on bundled OpenAPI JSON files

Open
#8,621 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Given a set of OpenAPI specs in YAML format. Running the code generation (e.g php) directly on it is fine. However, generating a bundled OpenAPI in JSON format (with the generator openapi) then running the code generation on that bundled JSON OpenAPI fails.

The expected behavior is that the bundled JSON OpenAPI behaves the same as the YAML format.

openapi-generator version
  • 4.3.1
  • 5.0.0
OpenAPI declaration file content or url

Given this file structure:

.
├── parent
│   └── spec
│       ├── endpoints
│       │   └── path.yaml
│       └── schemas
│           └── ApiError.yaml
└── spec
    ├── index.yaml

index.yaml

openapi: 3.0.2
info:
  title: test
  version: 1.0.0
servers:
  - url: http://127.0.0.1
    description: Localhost
paths:
  /a/b/{c}:
    $ref: '../parent/spec/endpoints/path.yaml#/paths/~1a~1b~1{c}'

path.yaml

openapi: 3.0.2
info:
  title: test
  version: 1.0.0
paths:
  /a/b/{c}:
    get:
      parameters:
        - in: path
          name: c
          schema:
            type: string
      responses:
        404:
          description: Disaster
          content:
            application/json:
              schema:
                $ref: '../schemas/ApiError.yaml#/components/schemas/NotFound'

ApiError.yaml

openapi: 3.0.2
info:
  title: Api Errors
  version: 1.0.0
paths: {}
components:
  schemas:
    NotFound:
      type: string
Generation Details

Default config

Steps to reproduce

This works:
openapi-generator generate -i spec/index.yaml -g php -o generated

This fails:

openapi-generator generate -i spec/index.yaml -g openapi -o generated
openapi-generator generate -i generated/openapi.json -g php -o generated

The errors:

Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 1, Warning count: 0
Errors:
	-attribute paths.'/a/b/{c}'(get).responses.404.content.'application/json'.schema.#/components/schemas/~1a~1b~1{c} is missing

	at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:541)
	at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:568)
	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:424)
	at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Related issues/PRs
Suggest a fix
  • The openapi generator should generate the equivalent version of the YAML version.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two commands using spec/index.yaml and compare the working YAML input with generated/openapi.json. Trace how the openapi generator bundles external references from path.yaml and ApiError.yaml, then verify that the bundled JSON can generate the PHP client without the reported missing-schema validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.