swagger-api / swagger-api/swagger-parser

Default server URL "/" is added automatically when parsing OpenAPI 3 spec

Open
#2,197 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

Description:
When I parse an OpenAPI 3.0 document using new OpenAPIV3Parser().readContents(...), a default server with URL "/" is automatically added if no servers are defined. This causes issues when the document is later used in Swagger UI or serialized with Json.mapper().writeValueAsString(...), as the unwanted "/" base path appears in the output.

Steps to Reproduce:

  1. Use the swagger-parser library to read an OpenAPI spec that has no servers section.
  2. Parse using:
OpenAPI openApi = new OpenAPIV3Parser().readContents(openApiString).getOpenAPI();
String openApiJson = Json.mapper().writeValueAsString(openApi);
  1. Observe that the resulting openApiJson includes:
"servers": [
  {
    "url": "/"
  }
]

Expected Behavior:
If no servers are defined in the input OpenAPI spec, the parser should not add a default server URL, or there should be an option to disable it.

Actual Behavior:
A server with URL "/" is automatically inserted into the servers list.

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 at OpenAPIV3Parser().readContents(...) and reproduce the issue with an OpenAPI 3 document that has no servers section. Trace where the default server is added, then verify serialization with Json.mapper().writeValueAsString(...); done means parsing no longer emits a "/" server when the input omits servers.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.