Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #12473
Closed
Open
Issue created May 26, 2022 by Administrator@rootContributor

[BUG] [PlantUML] Doesn't render fields for classes with inheritance (via allOf)

Created by: trreeves

Description

When multiple models are defined, with an implied inheritance structure, only fields for classes that have no inheritance are rendered.

Take the following model definitions, which are a simplified and modified extract from the Pet Store example.

definitions:
  Category:
    type: "object"
    properties:
      id:
        type: "integer"
        format: "int64"
      name:
        type: "string"
  Dog:
    type: "object"
    required:
      - "breed"
    allOf:
      - $ref: "#/definitions/Pet"
    properties:
      "breed":
        type: "string"
  Pet:
    type: "object"
    required:
    - "name"
    - "photoUrls"
    properties:
      id:
        type: "integer"
        format: "int64"
      category:
        $ref: "#/definitions/Category"
      name:
        type: "string"
        example: "doggie"

This implies a class structure represented by the following PlantUML, where Pet is a parent class, from which Dog inherits.

entity Category {
    id: Long
    name: String
}

entity Dog {
    breed: String
}

entity Pet {
    id: Long
    category: Category
    * name: String
    * photoUrls: List<String>
    tags: List<Tag>
    status: String
}

Pet <|--- Dog
Pet -- Category : category

However the current implementation, by accident of course, omits all fields for those classes/models that inherit from a parent class. e.g.

entity Dog {
}

entity Pet {
    id: Long
    category: Category
    * name: String
    * photoUrls: List<String>
    tags: List<Tag>
    status: String
}

The current implementation is only really concerned with what it classes as 'inline' models, which are identified with a naming convention of an 'allof' suffix, and neglects to consider the case of the allOf property referencing 'non-inline' models.

openapi-generator version

5.4.0, 6.0.0

OpenAPI declaration file content or url

Here's the full YAML to reproduce it.

swagger: "2.0"
info:
  version: "1.0.0"
  title: "Swagger Petstore"
paths:
  /pet/{petId}:
    get:
      tags:
      - "pet"
      summary: "Find pet by ID"
      description: "Returns a single pet"
      operationId: "getPetById"
      produces:
      - "application/xml"
      - "application/json"
      parameters:
      - name: "petId"
        in: "path"
        description: "ID of pet to return"
        required: true
        type: "integer"
        format: "int64"
      responses:
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/Pet"
        "400":
          description: "Invalid ID supplied"
        "404":
          description: "Pet not found"
      security:
      - api_key: []
definitions:
  Category:
    type: "object"
    properties:
      id:
        type: "integer"
        format: "int64"
      name:
        type: "string"
  Dog:
    type: "object"
    required:
      - "breed"
    allOf:
      - $ref: "#/definitions/Pet"
    properties:
      "breed":
        type: "string"
  Pet:
    type: "object"
    required:
    - "name"
    - "photoUrls"
    properties:
      id:
        type: "integer"
        format: "int64"
      category:
        $ref: "#/definitions/Category"
      name:
        type: "string"
        example: "doggie"
  ApiResponse:
    type: "object"
    properties:
      code:
        type: "integer"
        format: "int32"
      type:
        type: "string"
      message:
        type: "string"
externalDocs:
  description: "Find out more about Swagger"
  url: "http://swagger.io"
Generation Details

A simple CLI config will suffice to reproduce:

generatorName: plantuml
outputDir: <output-yaml>
inputSpec: <input-yaml>
templateDir: modules/openapi-generator/src/main/resources/plantuml
Steps to reproduce

Simply perform a plantuml generation with the input YAML provided above.

Related issues/PRs

No.

Suggest a fix

The generator code in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PlantumlDocumentationCodegen.java simply doesn't account for this case.

I have written a fix for it. I will contribute a PR very soon.

Assignee
Assign to
Time tracking