1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
package openapi3
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestPathsMustStartWithSlash(t *testing.T) {
spec := `
openapi: "3.0"
info:
version: "1.0"
title: sample
paths:
PATH:
get:
responses:
200:
description: description
`
for path, expectedErr := range map[string]string{
"foo/bar": "invalid paths: path \"foo/bar\" does not start with a forward slash (/)",
"/foo/bar": "",
} {
loader := NewLoader()
doc, err := loader.LoadFromData([]byte(strings.Replace(spec, "PATH", path, 1)))
require.NoError(t, err)
err = doc.Validate(loader.Context)
if expectedErr != "" {
require.EqualError(t, err, expectedErr)
} else {
require.NoError(t, err)
}
}
}
|