OpenAPITools / OpenAPITools/openapi-generator

[BUG][spring] definition of `type: object`, `items: # ...` passes as valid but isn't and causes compiler errors

Open
#10,922 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
Description

The spec below is invalid (an object has no items property), yet doesn't cause a validation error in either the Swagger Editor or when parsed by org.openapitools:openapi-generator-maven-plugin:5.3.0:

When used in a maven "build pipeline" with the spring generator, it results in a java.lang.AssertionError (apparently thrown by the Java compiler).

When using references to remote files (splitting the specification into multiple files) one can observe the following warning output (depending on setup) being logged:
https://github.com/OpenAPITools/openapi-generator/blob/0bb4f186ec7e776efbe370be89798ed2f659c9ff/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java#L458

openapi-generator version

5.3.0 (via maven plugin; cf. above)

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: object with items
  version: 1.0.0
servers:
- url: /
tags:
- name: pet
paths:
  /cat:
    get:
      tags:
      - pet
      operationId: getCats
      responses:
        200:
          description: Cats
          content:
            application/json:
              schema:
                type: object # should be array
                items:
                  type: string
Generation Details
  • org.openapitools:openapi-generator-maven-plugin:5.3.0
  • spring generator
Steps to reproduce

Paste the invalid YAML into the Swagger editor. It doesn't display an error.

Using a build pipeline, have the plugin generate model and api files. You should get the Java error.

Related issues/PRs

n/a

Suggest a fix

Clear validation error message

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 with the validation path used by the spring generator and inspect the referenced DefaultGenerator.java location around line 458. Reproduce the YAML with the Maven plugin and confirm how an object schema with items is handled. Done means the invalid schema produces a clear validation error before generation instead of a compiler failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
backend-api-design, 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.