Skip to content

Instantly share code, notes, and snippets.

@ybiquitous
Last active August 28, 2025 09:45
Show Gist options
  • Select an option

  • Save ybiquitous/65f7e5491f8b40c384561c4f96dd58cb to your computer and use it in GitHub Desktop.

Select an option

Save ybiquitous/65f7e5491f8b40c384561c4f96dd58cb to your computer and use it in GitHub Desktop.
redocly-cli v2.0.7 bug reproduction
openapi: '3.1.0'
info:
title: Example API
version: '1.0.0'
license:
name: MIT
servers:
- url: https://api.example.com/v1
openapi: '3.1.0'
paths:
/items:
get:
summary: Retrieve a list of items
responses:
'200':
description: A list of items
content:
application/json:
schema:
type: array
items:
type: string
{
"type": "module",
"dependencies": {
"@redocly/cli": "2.0.7"
},
"scripts": {
"join": "redocly join --without-x-tag-groups a.yml b.yml -o tmp.yml",
"bundle": "redocly bundle tmp.yml -o openapi.yml",
"postbundle": "rm -f tmp.yml",
"lint": "redocly lint openapi.yml --skip-rule security-defined",
"test": "npm run join && npm run bundle && npm run lint"
}
}
export default function plugin() {
return {
id: "my-plugin",
decorators: {
oas3: {
"add-servers": addServers,
},
},
};
}
const addServers = () => ({
Root: {
leave: (root) => {
root.servers = [
{
url: "https://api.example.com/v1",
},
];
},
},
});
decorators:
my-plugin/add-servers: on
plugins:
- plugin.js
extends:
- recommended
@ybiquitous
Copy link
Author

ybiquitous commented Aug 26, 2025

Run:

$ npm it
...
validating openapi.yml...
[1] openapi.yml:1:1 at #/openapi

Servers must be present.

1 | openapi: 3.1.0
2 | info:
3 |   title: Example API

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

It errored due to the no-empty-servers rule violation.

On the other hand, it has no problem with v2.0.4:

$ npm i @redocly/[email protected] -E
...

$ npm t
...
Woohoo! Your API description is valid. ๐ŸŽ‰
You have 5 warnings.

There is a difference with a generated openapi.yml between the versions:

   version: 1.0.0
   license:
     name: MIT
+servers:
+  - url: https://api.example.com/v1
 tags:
   - name: b_other
     x-displayName: other
 paths:
   /items:
-    servers: []
     get:
       summary: Retrieve a list of items
       responses:

@ybiquitous
Copy link
Author

@ybiquitous
Copy link
Author

Adding a customer decorator and running redocly bundle can work around the problem. Note that servers in a.yml is ignored.

Run:

$ npm it
...
Woohoo! Your API description is valid. ๐ŸŽ‰
You have 5 warnings.

Output openapi.yml:

openapi: 3.1.0
info:
  title: Example API
  version: 1.0.0
  license:
    name: MIT
servers:
  - url: https://api.example.com/v1
tags:
  - name: b_other
    x-displayName: other
paths:
  /items:
    servers: []
    get:
      summary: Retrieve a list of items
      responses:
        '200':
          description: A list of items
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
      tags:
        - b_other
components: {}

Ref https://redocly.com/docs/cli/guides/replace-servers-url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment