openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][Angular] Relative url with "-" in it is not recognized as relative

Open guillaumehottin opened this issue 3 years ago • 0 comments

Bug Report Checklist

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

When specifying a relative url in servers, the expected behaviour is for it to not prepend http://localhost to the basePath.

However, when this url has a "-" in it, it is not recognized as relative.

openapi-generator version

6.1.0

OpenAPI declaration file content or url
{
    "openapi": "3.0.2",
    "info": {
        "title": "FastAPI",
        "version": "0.1.0"
    },
    "servers": [
        {
            "url": "/api/micro-service"
        }
    ],
    "paths": {
        "/token": {
            "post": {
                "tags": [
                    "micro-service"
                ],
                "summary": "Get Token From Code",
                "operationId": "get_token_from_code_token_post",
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": {}
                            }
                        }
                    }
                }
            }
        }
    }
}
Generation Details

openapi-generator-cli generate -i openapi.json -g typescript-angular -o ./generated --additional-properties=fileNaming=kebab-case

Steps to reproduce

Use the provided openapi.json spec with the provided command line. Check in generated/api/micro-service.service.ts that the basePath is prepended with http://localhost

Related issues/PRs

The behaviour to prevent http://localhost to be prepended to basePath was added in #10057.

Suggest a fix

https://github.com/OpenAPITools/openapi-generator/blob/7ff47dc0bf6e65d0745042a38c7101b80cf4f71b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/URLPathUtils.java#L238

The regex used to check if a url is relative doesn't allow for non alphanumeric characters.

guillaumehottin avatar Sep 13 '22 15:09 guillaumehottin