OpenAPITools / OpenAPITools/openapi-generator
[BUG] relative path is prefixed with spec-url
Nobody has claimed this yet.
- 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 you generate with specs from URL the url is prefixed to the relative path from spec. From #10697 i would assume that a relative server-url is used as basePath in generated code.
openapi-generator version
5.4.0
5.3.1
OpenAPI declaration file content or url
https://petstore3.swagger.io/api/v3/openapi.json
Generation Details
The generator is used from npms @openapitools/openapi-generator-cli version 2.4.26
Via openapi-generator-cli version-manager list I choosed the versions mentioned above - same result.
Steps to reproduce
openapi-generator-cli generate -g typescript-angular -o /tmp/api -i https://petstore3.swagger.io/api/v3/openapi.json
The file /tmp/api/api/pet.service.ts looks as following:
...
export class PetService {
protected basePath = 'https://petstore3.swagger.io/api/v3';
...
expected is
...
export class PetService {
protected basePath = '/api/v3';
...
as "servers":[{"url":"/api/v3"} suggests
Related issues/PRs
#10057
Suggest a fix
Take the servers-url as-is for generating the basePath
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the documented openapi-generator-cli command with https://petstore3.swagger.io/api/v3/openapi.json and inspect /tmp/api/api/pet.service.ts. Trace how the relative servers URL becomes the generated basePath for typescript-angular. Done means the generated service uses /api/v3 rather than the full spec URL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100