Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
5 of 6 tasks
yima77 opened this issue Jan 18, 2024 · 1 comment
Open
5 of 6 tasks

Comments

@yima77
Copy link

yima77 commented Jan 18, 2024

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
@martin-mfg
Copy link
Contributor

The described issue still occurs in the latest master.

Please note that the shown input spec uses openapi: 3.1.0, which isn't fully supported yet by OpenAPI Generator. see e.g. #9083. When using openapi: 3.0.3 instead, the described problem does not occur. So you could use that as workaround for now.

For anyone who wants to work on this: The place where Item gets flagged as unused model is ModelUtils.getUnusedSchemas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants