DEXPRO-Solutions-GmbH / swaggerui

Gin handler to expose an OpenAPI spec via Swagger UI
Apache License 2.0
0 stars 0 forks source link

WithAddServerUrls Option not usable when linting API spec #4

Closed fabiante closed 1 year ago

fabiante commented 1 year ago

When using an API spec which defines an empty servers array and the WithAddServerUrls option ...

servers: []

... linting the API spec may fail with this error:

Servers must be a non-empty array.

 6 |   description: Aggregated API server which contains all APIs related to FREEZE
 7 |
 8 | servers: []
   | ^^^^^^^
 9 |
10 | security: []

Error was generated by the no-empty-servers rule.

If you omit the servers array, the error is kind of similar:

Servers must be present.

1 | openapi: 3.0.0
2 |
3 | info:

Error was generated by the no-empty-servers rule.

Reproduction

Use an API spec like specified and run a linter on it, i used: npx @redocly/cli lint openapi.yaml

Expected

To work arround this, I would add a dummy entry like this:

servers:
  - url: http://localhost/

and then I'd expect that the WithAddServerUrls would remove this dummy entry.

If this behaviour should be optional, we could change WithAddServerUrls to take a parameter such as this:

func WithAddServerUrls(removeExisting bool) Option {...}

If this parameter is true, it would remove any existing elements from the servers array.