Skip to content

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

@tedberg

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.

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