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
  • #669
Closed
Open
Issue created Jul 27, 2018 by Administrator@rootContributor

[JAVA][Client]: basePath defaults to "/" instead of "".

Created by: akehir

Description

I'm generating a typescript/angular client without a basePath in the API specification (json). This sets the basePath in the client to include a trailing "/", instead of not having a basePath as in Swagger.

The test cases specify a basePath "/v2" where both generators yield the same API client, and thus they don't detect this case.

However, if basePath is an empty string (""), or missing from the .json / .yaml, then the generated API clients differ from each other.

The swagger generator (2.3.1) yields:

protected basePath = 'https://host.example.com';

And the openapi generator yields:

protected basePath = 'https://host.example.com/';

This leads to an API call with double slashes: https://host.example.com//api/Common/Version instead of https://host.example.com/api/Common/Version.

openapi-generator version

3.1.1

OpenAPI declaration file content or url
{
  "swagger": "2.0",
  "info": {
    "version": "v1",
    "title": "Title"
  },
  "host": "host.example.com",
  "basePath": "",
  "schemes": [
    "https"
  ],
  "security":[{
    "basic" : []
  }],
"paths": {
    "/api/Common/Version": {
      "get": {
        "tags": [
          "Common"
        ],
        "summary": "Gets the version.",
        "operationId": "Common_Version",
        "consumes": [],
        "produces": [
          "application/json",
          "text/json",
          "application/xml",
          "text/xml",
          "text/javascript",
          "application/javascript",
          "application/json-p"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/Version"
            }
          }
        }
      }
    },
},
"definitions": {
    "Version": {
      "description": "Version information",
      "type": "object",
      "properties": {
        "Logic": {
          "description": "The logic version.",
          "type": "string"
        },
        "Data": {
          "description": "The data version.",
          "type": "string"
        }
      }
    },
},
"securityDefinitions": {
    "basic": {
      "type": "basic",
      "description": "Basic HTTP Authentication"
    }
  }
}

(for JSON code), so it becomes more readable. If it is longer than about ten lines, please create a Gist (https://gist.github.com) or upload it somewhere else and link it here. -->

Command line used for generation

mvn compile

pom file:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>ch.viu.a6calculator</groupId>
  <artifactId>a6calculator</artifactId>
  <version>1</version>
  <dependencies>
    <!--<dependency>-->
      <!--<groupId>org.openapitools</groupId>-->
      <!--<artifactId>openapi-generator-maven-plugin</artifactId>-->
      <!--<version>3.1.1</version>-->
    <!--</dependency>-->
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>3.1.1</version>
        <!--<groupId>io.swagger</groupId>-->
        <!--<artifactId>swagger-codegen-maven-plugin</artifactId>-->
        <!--<version>2.3.1</version>-->
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <!--<inputSpec>https://taxapi.taxware.ch/swagger/docs/v1</inputSpec>-->
              <inputSpec>${project.basedir}/openapi/tax/v1.json</inputSpec>
              <generatorName>typescript-angular</generatorName>
              <!--<language>typescript-angular</language>-->
              <output>${project.basedir}/src/generated/tax</output>
              <configOptions>
                <ngVersion>6.0.0</ngVersion>
              </configOptions>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
Steps to reproduce

Generate the client, and look at the basePath in the service files.

Related issues/PRs

n/a

Suggest a fix/enhancement

I believe this should be fixed so that the generated basePath never ends in a "/".

Assignee
Assign to
Time tracking