Skip to content

Generate simply named, reusable model objects from simple form of $ref to an external yaml file #291

Closed

Description

@tedberg

I have been using the openapi-generator project for several years. With that, one could create a ref to a component as:

responses:
  '200':
    description: OK
    content:
      'application/json':
        schema:
          $ref: './components/schemas/bar/BarResponse.yaml'

And in BarResponse.yaml:

title: Bar Response
type: object
properties:
  first:
    type: string
  second:
    type: string

The generator would generate a BarResponse[DTO].java file, using the filename to drive the class name. Switching to openapi-processor, the same yaml generates a computed name such as FooGetResponse200[DTO].java.

This can be fixed by updating BarResponse.yaml to add the first 3 lines (and fix indentation):

components:
  schemas:
    BarResponse:
title: Bar Response
type: object
properties:
  first:
    type: string
  second:
    type: string

Then fixing the $ref code to be:

responses:
  '200':
    description: OK
    content:
      'application/json':
        schema:
          $ref: './components/schemas/bar/BarResponse.yaml#/components/schemas/BarResponse'

solves the issue, with the generated model back to BarResponse[DTO].java.

Feature request is to leverage the external filename to determine the model name to bring feature parity with the openapi-generator. I'm not exactly sure if one of the two external file formats is officially correct and the other not, but it is less verbose to be able to use the shorter notation.

Activity

  1. tedberg commented on Aug 14, 2025

    @tedberg
    Author

    This is similar to #189, but that issue is talking about inline definitions.

  2. hauner commented on Aug 14, 2025

    @hauner
    Member

    Sounds reasonable, will be interesting to see how easy it is to get at the filename. :-)

  3. added this to the next milestone on Aug 25, 2025
  4. added a commit that references this issue on Sep 7, 2025
  5. modified the milestones: next, 2025.5 on Sep 11, 2025
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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions