swagger-api / swagger-api/swagger-ui
URL Fragment should be removed from path when building the request
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Q&A (please complete the following information)
- OS: [e.g. macOS] Linux
- Browser: [e.g. chrome, safari] chrome
- Version: [e.g. 22] 79
- Method of installation: [e.g. npm, dist assets] dist
- Swagger-UI version: [e.g. 3.10.0] master
- Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0] 3.0
Content & configuration
Example Swagger/OpenAPI definition:
---
openapi: 3.0.2
info:
title: Swagger Petstore - OpenAPI 3.0
version: 1.0.5
servers:
- url: "/api/v3"
paths:
"/pet/findByStatus#test":
get:
tags:
- pet
summary: Finds Pets by status
description: Multiple status values can be provided with comma separated strings
operationId: findPetsByStatus
parameters:
- name: status
in: query
description: Status values that need to be considered for filter
required: false
explode: true
schema:
type: string
default: available
enum:
- available
- pending
- sold
responses:
'200':
description: successful operation
content:
application/xml:
schema:
type: array
items:
"$ref": "#/components/schemas/Pet"
application/json:
schema:
type: array
items:
"$ref": "#/components/schemas/Pet"
'400':
description: Invalid status value
components:
schemas:
Category:
type: object
properties:
id:
type: integer
format: int64
example: 1
name:
type: string
example: Dogs
xml:
name: category
Tag:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: tag
Pet:
required:
- name
- photoUrls
type: object
properties:
id:
type: integer
format: int64
example: 10
name:
type: string
example: doggie
category:
"$ref": "#/components/schemas/Category"
photoUrls:
type: array
xml:
wrapped: true
items:
type: string
xml:
name: photoUrl
tags:
type: array
xml:
wrapped: true
items:
"$ref": "#/components/schemas/Tag"
status:
type: string
description: pet status in the store
enum:
- available
- pending
- sold
xml:
name: pet
ApiResponse:
type: object
properties:
code:
type: integer
format: int32
type:
type: string
message:
type: string
xml:
name: "##default"
requestBodies:
Pet:
description: Pet object that needs to be added to the store
content:
application/json:
schema:
"$ref": "#/components/schemas/Pet"
application/xml:
schema:
"$ref": "#/components/schemas/Pet"
Describe the bug you're encountering
If a path contains a fragment, the query params are appended after the fragment. Clients (browser, curl, ...) don't send what is after the fragment so the query params are not sent. When building the URL for the request, the fragment should be searched and removed.
To reproduce...
Steps to reproduce the behavior:
- Use the example YAML in swagger-ui
- Click on /pet/findByStatus#test "Try it out" and execute
- A request to /pet/findByStatus is made (without the status query param)
Expected behavior
A request to /pet/findByStatus?status=available is made.
Additional context or thoughts
Using a fragment is a common workaround for the impossibility to have multiple operations on the same path+method.
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
Reproduce the issue with the example YAML and the Try it out flow for /pet/findByStatus#test, then trace the request URL-building entry point used by Swagger UI. Verify that the fragment is excluded before query parameters are added and that the resulting request is /pet/findByStatus?status=available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100