Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪲 No further validation in the presence of anyOf. Always true. #890

Closed
micronull opened this issue Dec 29, 2023 · 0 comments · Fixed by #892
Closed

🪲 No further validation in the presence of anyOf. Always true. #890

micronull opened this issue Dec 29, 2023 · 0 comments · Fixed by #892

Comments

@micronull
Copy link
Contributor

micronull commented Dec 29, 2023

The reason for this change: #850

Test case (add in openapi3filter/validate_request_test.go):

We are waiting for the error minimum string length is 17, but there is no error.

func TestValidateRequestInvalidStringLength(t *testing.T) {
	const spec = `
openapi: 3.0.0
info:
  title: 'Validator'
  version: 0.0.1
paths:
  /tech:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                vehicle:
                  $ref: "#/components/schemas/Vehicle"
      responses:
        '200':
          description: Ok

components:
  schemas:
    Vehicle:
      type: object
      properties:
        identifiers:
          type: object
          properties:
            vin:
              type: string
              minLength: 17
              maxLength: 17
            body:
              type: string
              minLength: 7
              maxLength: 15
          anyOf:
            - required: [ vin ]
            - required: [ body ]
`

	body := strings.NewReader(`{"vehicle":{"identifiers":{"vin":"BAD"}}}`)
	req, err := http.NewRequest(http.MethodPost, "/tech", body)
	require.NoError(t, err)

	req.Header.Add("Content-Type", "application/json")

	router := setupTestRouter(t, spec)
	route, pathParams, err := router.FindRoute(req)
	require.NoError(t, err)

	err = ValidateRequest(context.Background(), &RequestValidationInput{
		Request:     req,
		PathParams:  pathParams,
		Route:       route,
		QueryParams: req.URL.Query(),
	})
	require.ErrorContains(t, err, "minimum string length is 17")
}

Similar properties are similarly not validated. minLength is taken as an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant