Iakov Burtsev
Iakov Burtsev

Reputation: 395

How to generate a base model class that has no properties using openapi-generator-maven-plugin

I'm using maven plugin for my java project:

            <groupId>org.openapitools</groupId>
            <artifactId>openapi-generator-maven-plugin</artifactId>
            <version>4.3.1</version>

And in openapi config file (yml) I described one post request and response models for it:

post:
  tags:
    - instance
  summary: createInstances
  description: Creates instances for given ids
  operationId: createInstances
  requestBody:
    description: Params for creation
    required: true
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/CreateInstancesRequest'
  responses:
    200:
      description: Ok
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/CreateInstancesResponse'
    206:
      description: Partial Content
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PartialCreateInstancesResponse'

CreateInstancesResponse:
  type: object

PartialCreateInstancesResponseResponse:
  allOf:
    - $ref: '#/components/schemas/CreateInstancesResponse'
  required:
    - failedIds
  properties:
    failedIds:
      $ref: '#/components/schemas/Ids'

I expect that it will generate a base java class (CreateInstancesResponse) without fields and an inherited class (PartialCreateInstancesResponse). It is curious that PartialCreateInstancesResponse class is generated. But the base class is not generated. Could you help me please to solve the problem?

Upvotes: 1

Views: 2895

Answers (1)

user3778881
user3778881

Reputation: 28

Looks like it is not supported yet. You can refer an open issue here for this.

A work around can be, add dummy property in super class.

"Pet": {
    "title": "AbstractPet",
    "type": "object",
    "properties": {
        "dummyProperty": {
            "type": "string",
            "description": "Workaround - OpenAPI generator does not consider definitions without properties"
        }
    },
    "description": "model containing all the details of a pet",
    "discriminator": {
        "propertyName": "petTypeName"
    }
}

Upvotes: 1

Related Questions