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
  • #5008
Closed
Open
Issue created Jan 15, 2020 by Administrator@rootContributor5 of 5 checklist items completed5/5 checklist items

[BUG][tyescript-axios] withSeparateModelsAndApi option throws exception

Created by: boenrobot

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?
Description

I would like to generate a typescript-axios client with separate models. I can successfully generate one without separate ones, but with separate ones, an exception is thrown.

openapi-generator version

4.2.2

OpenAPI declaration file content or url

The spec is dynamically generated by a Nest application (the very reason I want to use a generator to begin with is to keep it in sync). Here's the one that produces this error:

{
  "openapi": "3.0.0",
  "info": {
    "title": "Frontoffice",
    "description": "API docs",
    "version": "0.1",
    "contact": {}
  },
  "tags": [],
  "servers": [],
  "components": {
    "schemas": {
      "RegisterRequestDto": {
        "type": "object",
        "properties": {
          "username": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9]+([a-zA-Z0-9][_\\-][a-zA-Z0-9])*[a-zA-Z0-9]+$"
          },
          "password": {
            "type": "string",
            "minLength": 8
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string",
            "description": "Phone number. Can contain arbitrary symbols for readability, but only the digits, and an optional leading plus are accepted.",
            "pattern": "[0-9]+"
          }
        },
        "required": [
          "username",
          "password",
          "email",
          "phone"
        ]
      },
      "PlayerInsertResultDto": {
        "type": "object",
        "properties": {
          "playerId": {
            "type": "number"
          }
        },
        "required": [
          "playerId"
        ]
      },
      "ConflictException": {
        "type": "object",
        "properties": {}
      },
      "UnauthorizedException": {
        "type": "object",
        "properties": {}
      }
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "ApiController-getIndex",
        "responses": {
          "200": {
            "description": ""
          }
        }
      }
    },
    "/register": {
      "get": {
        "operationId": "RegisterApiController-getIndex",
        "responses": {
          "200": {
            "description": ""
          }
        }
      },
      "post": {
        "operationId": "RegisterApiController-postIndex",
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RegisterRequestDto"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PlayerInsertResultDto"
                }
              }
            }
          },
          "409": {
            "description": "If the player already exists",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConflictException"
                }
              }
            }
          }
        }
      }
    },
    "/login": {
      "get": {
        "operationId": "LoginApiController-getIndex",
        "responses": {
          "200": {
            "description": ""
          }
        }
      },
      "post": {
        "operationId": "LoginApiController-postIndex",
        "responses": {
          "201": {
            "description": "A sanitized player object"
          },
          "401": {
            "description": "On invalid credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedException"
                }
              }
            }
          }
        }
      }
    },
    "/_schema": {
      "get": {
        "operationId": "SwaggerApiController-getSchema",
        "responses": {
          "200": {
            "description": ""
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "operationId": "SwaggerApiController-getDocument",
        "responses": {
          "200": {
            "description": ""
          }
        }
      }
    }
  }
}
Command line used for generation

npx openapi-generator generate -i openapi.json --config .\openapi-generate.json -g typescript-axios -o openapi

Steps to reproduce
  • Set withSeparateModelsAndApi to true in the --config file.
  • Run the command above command.

Output in console:

Exception in thread "main" java.lang.RuntimeException: apiPackage and modelPackage must be defined
        at org.openapitools.codegen.languages.TypeScriptAxiosClientCodegen.processOpts(TypeScriptAxiosClientCodegen.java:117)
        at org.openapitools.codegen.DefaultGenerator.configureGeneratorProperties(DefaultGenerator.java:196)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:913)
        at org.openapitools.codegen.cmd.Generate.run(Generate.java:416)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61)

as opposed to withSeparateModelsAndApi set to false, which finishes with no errors.

Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking