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
  • #10056
Closed
Open
Issue created Jul 28, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][JAVA] Bug the getServerURL method doesnt respect relative urls as described in the openapi definition

Created by: code1x1

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The generator prefixes the basePath with http://localhost when servers[0].url == '/api' resulting in a basePath == 'http://localhost/api' if the generated client is used in multiple domains the basePath should be set relative to make the generated client more flexible i think??

Also the openapi specs explicitly state that the url may be relative which isnt the possible with this generator at the moment 4.8.5.1 Fixed Fields

REQUIRED. A URL to the target host. This URL supports Server Variables and MAY be relative, to indicate that the host location is relative to the location where the OpenAPI document is being served. Variable substitutions will be made when a variable is named in {brackets}.

openapi-generator version

5.2 and master

OpenAPI declaration file content or url

This is an example spec.yaml

openapi: "3.0.3"
info: 
  title: "test api"
  description: "unofficial api test"
  termsOfService: "https://localhost/api/"
  contact: 
    name: "API Support"
    url: "https://localhost/helpdesk/"
    email: "info@localhost"
  license: 
    name: MIT
  version: v1
servers: 
  - url: "/api"
tags: 
  - name: account
paths:
  "/account/v1/json/login"
    post: 
      description: ""
      tags: 
        - account
      operationId: "account.login"
      responses: 
        default: 
          description: ""
          content: 
            "application/json": 
              schema: 
                "$ref": "#/components/schemas/account.login.response.default"
      requestBody: 
        description: ""
        content: 
          "application/json": 
            schema: 
              type: object
              properties: 
                emailAddress: 
                  type: string
                password: 
                  type: string
                  
Generation Details
Steps to reproduce
  1. save the example file as api.yaml
  2. run ./openapi-generator-cli.jar generate -g typescript-axios -i api.yaml -o client
  3. the generated client library added http://localhost to the relative url
Related issues/PRs
Suggest a fix

https://github.com/OpenAPITools/openapi-generator/blob/870ef3a87ac5a9751198ea0f0e36c821563b5e61/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/URLPathUtils.java#L69

Assignee
Assign to
Time tracking