`just openapi [dir]` (go run ./cmd/openapi) writes openapi.json (3.1) and openapi-3.0.json without a database or configuration. A test checks it matches the spec the server serves.
29 lines
711 B
Go
29 lines
711 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRunWritesBothVersions(t *testing.T) {
|
|
dir := t.TempDir()
|
|
require.NoError(t, run(dir))
|
|
|
|
for name, version := range map[string]string{"openapi.json": "3.1.0", "openapi-3.0.json": "3.0.3"} {
|
|
data, err := os.ReadFile(filepath.Join(dir, name))
|
|
require.NoError(t, err)
|
|
var spec struct {
|
|
OpenAPI string `json:"openapi"`
|
|
Paths map[string]any `json:"paths"`
|
|
}
|
|
require.NoError(t, json.Unmarshal(data, &spec), name)
|
|
assert.Equal(t, version, spec.OpenAPI, name)
|
|
assert.Contains(t, spec.Paths, "/api/v1/music/info", name)
|
|
}
|
|
}
|