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
  • #4804
Closed
Open
Issue created Dec 16, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][typescript-axios] Unnecessary imports occurs when using nested model in allOf

Created by: tanmen

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

If allOf is used, it tries to import a nested model that is not used. import must be used or deleted.

target schemas

    Response:
      type: string
      example: success
      enum:
        - success
        - error
    Box:
      type: object
      properties:
        id:
          type: number
          example: 1
        name:
          type: string
          example: inbox
        box:
          $ref: '#/components/schemas/BoxInBox'
    BoxInBox:
      type: object
      properties:
        id:
          type: number
          example: 1
        name:
          type: string
          example: inbox
    BoxesResponse:
      allOf:
        - $ref: '#/components/schemas/Response'
        - $ref: '#/components/schemas/Box'

generated typescript file

import { Box } from './box';
import { BoxInBox } from './box-in-box';
import { Response } from './response';

/**
 * 
 * @export
 * @interface BoxesResponse
 */
export interface BoxesResponse {
    /**
     * 
     * @type {string}
     * @memberof BoxesResponse
     */
    status: BoxesResponseStatusEnum;
    /**
     * 
     * @type {number}
     * @memberof BoxesResponse
     */
    id?: number;
    /**
     * 
     * @type {string}
     * @memberof BoxesResponse
     */
    name?: string;
    /**
     * 
     * @type {BoxInBox}
     * @memberof BoxesResponse
     */
    box?: BoxInBox;
}

/**
    * @export
    * @enum {string}
    */
export enum BoxesResponseStatusEnum {
    Success = 'success',
    Error = 'error'
}

expected

import { Box } from './box';
import { Response } from './response';

/**
 * 
 * @export
 * @interface BoxesResponse
 */
export type BoxesResponse = Response & Box;
openapi-generator version

4.2.2

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  title: My application
  version: 1.0.0
  description: My application
tags:
  - name: Box
paths:
  /boxes:
    get:
      summary: Box list
      description: Box list
      operationId: showBoxes
      tags:
        - Box
      responses:
        200:
          description: Box list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BoxesResponse'
components:
  schemas:
    Response:
      type: string
      example: success
      enum:
        - success
        - error
    Box:
      type: object
      properties:
        id:
          type: number
          example: 1
        name:
          type: string
          example: inbox
        box:
          $ref: '#/components/schemas/BoxInBox'
    BoxInBox:
      type: object
      properties:
        id:
          type: number
          example: 1
        name:
          type: string
          example: inbox
    BoxesResponse:
      allOf:
        - $ref: '#/components/schemas/Response'
        - $ref: '#/components/schemas/Box'
Command line used for generation
openapi-generator generate -i openapi.yml -g typescript-axios -o apis -p withSeparateModelsAndApi=true --api-package apis --model-package models
Steps to reproduce

N/A

Related issues/PRs

#4629 (closed)

Suggest a fix

#4805

Assignee
Assign to
Time tracking