OpenAPITools / OpenAPITools/openapi-generator

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

Open
#13,412 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/URLPathUtils.java around the referenced line, then reproduce the issue using the provided openapi.json and the typescript-angular generation command. Done means a server URL such as /api/micro-service remains relative and the generated api/micro-service.service.ts does not prepend http://localhost.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, java, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.