vacuum is the worlds fastest OpenAPI 3, OpenAPI 2 / Swagger linter and quality analysis tool. Built in go, it tears through API specs faster than you can think. vacuum is compatible with Spectral rulesets and generates compatible reports.
I'm getting the following error against $refs when linting or bundling non-YAML files. For example, if I have a x-codeSamples property and a $ref: 'echo.go'.
Redocly handles this use case (perhaps exclusively to their implementation), so in the spirit of trying to use Vacuum exclusively, I'm wondering if there's a workaround or enhancement that could be made. As reference, here's their help guide and starter project.
Error
ERROR unable to open the rolodex file, check specification references and base path
├ file: /Users/darren/dev/repo/torchlight/backend-services/api_specs/openapi/echo.go
└ error: open /Users/darren/dev/repo/torchlight/backend-services/api_specs/openapi/echo.go: file does not exist
All files in the same directory, though same result if they're nested in folders
Also tried using the -p flag as well, but no difference
Spec files used
openapi.yaml
$ref near bottom of sample
openapi: 3.1.0
info:
version: 1.0.0
title: Example API
termsOfService: https://example.com/terms/
contact:
name: Contact our support
email: contact@example.com
url: http://example.com/contact
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
description: >
This is an **example** API to demonstrate features of the OpenAPI
specification.
tags:
- name: Echo
description: "Example echo operations."
servers:
- url: https://{tenant}/api/v1
variables:
tenant:
default: www
description: Your tenant id
- url: https://tl.com/api/v1
paths:
'/echo':
get:
tags:
- Echo
summary: Echo test
description: Returns a hello
operationId: echo
security:
- basic_auth: []
responses:
'200':
description: OK
content:
application/json:
schema:
type: string
examples:
response:
value: 'Hello world!'
'400':
description: Unauthorized
x-codeSamples:
- lang: Go
source:
$ref: 'echo.go'
components:
securitySchemes:
basic_auth:
description: Basic auth
type: http
scheme: basic
echo.go
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, world!")
})
fmt.Println("Server listening on :8080...")
http.ListenAndServe(":8080", nil)
}
Redocly equivalent
Recdocly's CLI bundles this just fine with an equivalent command redocly bundle openapi.yaml -o ../dist/openapi.yaml. The behavior is that the code file is inserted as either an escaped string or multiline string (seems to vary based on code language) retaining indentation and newlines.
For example, the above with Redocly would result in the following being generated in the bundled file.
x-codeSamples:
- lang: Go
source: "package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n)\n\nfunc main() {\n\thttp.HandleFunc(\"/echo\", func(w http.ResponseWriter, r *http.Request) {\n\t\tfmt.Fprint(w, \"Hello, world!\")\n\t})\n\n\tfmt.Println(\"Server listening on :8080...\")\n\thttp.ListenAndServe(\":8080\", nil)\n}\n"
Alternatives tried
One workaround I found was that allowed Vacuum to pass and bundle is the following. However, this means the sample code files are not "testable" as part of our test suite, so that adds some inconvience.
Use a YAML file as the source for the code sample (instead of the code sample's language extension)
Reference the full object in the x-codeSamples array item. For example:
In openapi.yaml file
x-codeSamples:
- $ref: 'get.yaml'
In echo.yaml file
lang: Go
source: |-
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, world!")
})
fmt.Println("Server listening on :8080...")
http.ListenAndServe(":8080", nil)
}
I'm getting the following error against $refs when linting or bundling non-YAML files. For example, if I have a
x-codeSamples
property and a$ref: 'echo.go'
.Redocly handles this use case (perhaps exclusively to their implementation), so in the spirit of trying to use Vacuum exclusively, I'm wondering if there's a workaround or enhancement that could be made. As reference, here's their help guide and starter project.
Error
Commands
vacuum lint -bda openapi.yaml
andvacuum bundle openapi.yaml ../dist/openapi.yaml
openapi
-p
flag as well, but no differenceSpec files used
openapi.yaml
$ref near bottom of sample
echo.go
Redocly equivalent
Recdocly's CLI bundles this just fine with an equivalent command
redocly bundle openapi.yaml -o ../dist/openapi.yaml
. The behavior is that the code file is inserted as either an escaped string or multiline string (seems to vary based on code language) retaining indentation and newlines.For example, the above with Redocly would result in the following being generated in the bundled file.
Alternatives tried
One workaround I found was that allowed Vacuum to pass and bundle is the following. However, this means the sample code files are not "testable" as part of our test suite, so that adds some inconvience.
Reference the full object in the
x-codeSamples
array item. For example: In openapi.yaml fileIn echo.yaml file