Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Talakafafi opened this issue May 29, 2025 · 0 comments
Open

Comments

@Talakafafi
Copy link

Talakafafi commented May 29, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant