OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-axios] Path level servers overrides are ignored

Open
#12,031 0 comments 2 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

Path level servers overrides are ignored. Using the provided sample both https://api.pet.com/v2 and https://api.user.com/v2 are not included within the generated code. This is an issue with all specs tested.

openapi-generator version

5.4.0

OpenAPI declaration file content or url

openapi-test.zip

servers:
- url: https://api.root.com/v3
# ... 
paths:
  /pet:
    servers:
      - url: https://api.pet.com/v2
   # ...
   /user:
    servers:
      - url: https://api.user.com/v2
Generation Details

npx @openapitools/openapi-generator-cli generate -i openapi-test.yaml -g typescript-axios -o sdk-test

Steps to reproduce
  • Generate the SDK using the provided spec.
  • Verify that the generated SDK ignores servers defined within paths.
Related issues/PRs

Related issues with a different SDK #1694. #10639

Suggest a fix

Servers defined within paths should be used for those paths which have been defined.

Generator for Javascript works pretty well, code envolved:
https://github.com/OpenAPITools/openapi-generator/blob/5d68bd6a03f0c48e838b4fe3b98b7e30858c0373/modules/openapi-generator/src/main/resources/Javascript/api.mustache#L90-L100

In typescript-axios i think must to send something like:

 let basePaths = [<#servers>'<url>'<^-last>, </-last></servers>]; 
 let basePath = basePaths[0]; // by default use the first one in

instead of BASE_PATH

Check here https://github.com/OpenAPITools/openapi-generator/blob/5d68bd6a03f0c48e838b4fe3b98b7e30858c0373/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache#L227

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/resources/typescript-axios/apiInner.mustache around line 227, then compare the referenced Javascript/api.mustache server handling. Generate the SDK from the provided openapi-test.yaml with the shown typescript-axios command and verify that /pet and /user use their path-level server URLs rather than only the root server.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.