Skip to content

Send API Request fails to construct URL when endpoint has multiple path parametersΒ #1261

@jonahlindau

Description

@jonahlindau

Describe the bug

When using the "Send API Request" feature on an endpoint that has multiple path parameters, the generated curl command and request URL only include the base server URL, completely omitting the path with substituted parameter values. Endpoints with a single path parameter work correctly.

Expected behavior

For an endpoint like /data/{param1}/{param2}.json with path parameters:

param1 = "value1"
param2 = "value2"
Query parameter id = "abc123"
The generated curl should be:

bash
curl -L 'https://api.example.com/v2/data/value1/value2.json?id=abc123' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer <token>'

Current behavior

The generated curl command is:

bash
curl -L 'https://api.example.com/v2' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer <token>'

The entire path /data/{param1}/{param2}.json is missing. Only the base server URL is used.

Possible solution

The URL construction logic in the theme's API explorer component likely fails to iterate through and substitute all path parameters when there are multiple. The substitution logic should handle an arbitrary number of path parameters.

Steps to reproduce

  1. Create an OpenAPI spec with an endpoint containing two or more path parameters:
json
{
  "openapi": "3.0.2",
  "servers": [{ "url": "https://api.example.com/v2" }],
  "paths": {
    "/data/{param1}/{param2}.json": {
      "get": {
        "summary": "Get data",
        "parameters": [
          {
            "name": "param1",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["option1", "option2", "option3"]
            }
          },
          {
            "name": "param2",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["typeA", "typeB", "typeC"]
            }
          },
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": { "description": "Success" }
        }
      }
    }
  }
}
  1. Generate the API docs: npm run gen-api-docs
  2. Start the dev server: npm start
  3. Navigate to the generated endpoint page
  4. Select values from the path parameter dropdowns and enter a query parameter value
  5. Click "Send API Request"
  6. Observe the curl command - the path is missing (also shows as an error in console)

Screenshots

Context

Using this on my documentation website for my company, our API paths often have multiple path parameters. The use case is really that we have different types of aggregate feeds (by minute, by 5 minute, etc.) with the same schemas, so I don't want to use separate pages for each feed, I want to just be able to have a feedName enum that can modify which feed we want as a path parameter.

Your Environment

  • Version used:
  • docusaurus-plugin-openapi-docs: 4.0.1 (also tested in 4.5.1)
  • docusaurus-theme-openapi-docs: 4.0.1 (also tested in 4.5.1)
  • Docusaurus: 3.7.0
  • Node.js: 18.20.7
  • OS: macOS
  • Chrome

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions