OpenAPITools / OpenAPITools/openapi-generator

[BUG] validate command reports unused model when the model is referred for array items

Open
#17,648 1 comment 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

When openapi-generator-cli validate is run on an OpenAPI in either YAML or JSON format, it reports a warning about an unused model when that model is referred by an array item. It is clearly an error since the model is referred so it isn't unused. The same warning doesn't appear when the model is referred by an object.

openapi-generator version

6.3.0, 7.2.0 and 7.3.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  version: DEVELOPMENT
  title: Title
  description: |
    Sample API
paths:
  /api:
    get:
      operationId: accessAPI
      summary: Access the API
      description: API description
      requestBody:
        description: Information about the access
        content:
          application/json:
            schema:
              type: object
              required:
                - info
              properties:
                info:
                  type: array
                  description: A list of info items
                  items:
                    $ref: '#/components/schemas/Item'
      responses:
        '200':
          description: OK response
components:
  schemas:
    Item:
      type: object
      description: Info item
      properties:
        summary:
          type: string
          description: Summary
        detail:
          type: string
          description: Detail
Generation Details
Steps to reproduce

Put the OpenAPI spec in a YAML file and run openapi-generator-cli validate on it, such as:

$ openapi-generator-cli validate -i sample.yaml

It will generate the following output:

Validating spec (sample.yaml)
Warnings:
        - Unused model: Item

[info] Spec has 1 recommendation(s).
Related issues/PRs
Suggest a fix

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 issue with the YAML declaration in sample.yaml and run openapi-generator-cli validate -i sample.yaml. Trace how the validate command identifies referenced models, comparing the array-item reference with the object reference. Done means the Item schema is no longer reported as unused when referenced through array items.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.