-
-
Notifications
You must be signed in to change notification settings - Fork 483
Closed
Description
As per #526 I'd expect schema examples to be validated as well, but I can't get these tests to fail validation using either examples or example (this one not implemented afaik). Am I missing something in the code below?
package openapi3
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestExamplesValidation(t *testing.T) {
spec := []byte(`
openapi: 3.0.0
paths:
/user:
post:
description: User creation.
operationId: createUser
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/CreateUserRequest"
examples:
BadUser:
$ref: '#/components/examples/BadUser'
description: Created user object
required: true
responses:
"201":
content:
application/json:
schema:
$ref: "#/components/schemas/CreateUserResponse"
description: successful operation
# security:
# - api_key: []
summary: creates a new user
tags:
- user
components:
schemas:
CreateUserRequest:
description: represents a new User
example:
username: "]bad["
email: bad
password: short
required:
- username
- email
- password
properties:
username:
type: string
pattern: "^[ a-zA-Z0-9_-]+$"
minLength: 3
email:
type: string
pattern: "^[A-Za-z0-9+_.-]+@(.+)$"
password:
type: string
minLength: 7
title: a User
type: object
CreateUserResponse:
description: represents the response to a User creation
properties:
access_token:
type: string
user_id:
format: int64
type: integer
type: object
# implemented in #526
examples:
BadUser:
value:
username: "]bad["
email: bad
password: short
info:
title: An API
version: 1.2.3.4
`)
loader := NewLoader()
doc, err := loader.LoadFromData(spec)
require.NoError(t, err)
err = doc.Validate(loader.Context)
require.Error(t, err) // FAIL
}EDIT: well this explains it:
// Validate returns an error if Example does not comply with the OpenAPI spec.
func (example *Example) Validate(ctx context.Context) error {
return nil // TODO
}Is this being worked on/planned/would accept a PR for it?
Metadata
Metadata
Assignees
Labels
No labels