[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
- save the example file as
api.yaml
- run
./openapi-generator-cli.jar generate -g typescript-axios -i api.yaml -o client
- the generated client library added http://localhost to the relative url