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

Validating Path Parameters with Regex #43

Closed
Sakdow opened this issue Dec 21, 2023 · 2 comments · Fixed by #58
Closed

Validating Path Parameters with Regex #43

Sakdow opened this issue Dec 21, 2023 · 2 comments · Fixed by #58

Comments

@Sakdow
Copy link

Sakdow commented Dec 21, 2023

In the context of the following YAML code snippet from the OpenAPI specification:

/companies/{company_id}:
  patch:
    parameters:
      - name: company_id
        in: path
        required: true
        example: 9de0691c-bc8d-409b-8f40-75d4f45db2f3
        schema:
          type: string
          pattern: '/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i'

I am attempting to validate the company_id path parameter using a regular expression. However, despite my efforts, it seems that the validation is not working as expected.

func (s Spec) ValidateRequest(request *http.Request) error {
	valid, errs := v.validator.ValidateHttpRequest(request)
	if len(errs) > 0 {
		for _, err := range errs {
			fmt.Println(err)
		}
	}

	if !valid {
		return fmt.Errorf("request is not valid")
	}

	return nil
}

Or with :

func (s Spec) FindRoute(request *http.Request) error {
	_, errs, _ := paths.FindPath(request, v.document)
	if len(errs) > 0 {
		return fmt.Errorf("request is not valid : %v", errs)
	}

	valid, errs := v.validator.GetParameterValidator().ValidatePathParams(request)
	if len(errs) > 0 {
		for _, err := range errs {
			fmt.Println(err)
		}

		return fmt.Errorf("request is not valid: %v", errs)
	}

	if !valid {
		return fmt.Errorf("request is not valid")
	}

	return nil
}
@daveshanley
Copy link
Member

This is strange. I will look into this for you when I can.

@emilien-puget
Copy link
Contributor

i think what needs to be done is akin to what i did there #55, but for the path parameters, it seems like there is only json schema validation for object types of parameters

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

Successfully merging a pull request may close this issue.

3 participants