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

OAS 3 String format validation not working in path #724

Closed
zekth opened this issue Dec 29, 2022 · 5 comments
Closed

OAS 3 String format validation not working in path #724

zekth opened this issue Dec 29, 2022 · 5 comments

Comments

@zekth
Copy link
Contributor

zekth commented Dec 29, 2022

Seems like the string format validation does not seem to work in path

paths:
  /uuid-pattern/{param}:
    get:
      parameters:
        - in: path
          name: param
          required: true
          schema:
            type: string
            pattern: '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
            minLength: 36
            maxLength: 36
      responses:
        '200':
          description: success
  /uuid-format/{param}:
    get:
      parameters:
        - in: path
          name: param
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: success

In the previous example /uuid-pattern/foobar returns properly an error, which can be casted as multierror with 2 errors but the uuid-format/foobar passes the validation.

Seems like the format is handled in the codebase:

func NewUUIDSchema() *Schema {
return &Schema{
Type: TypeString,
Format: "uuid",
}
}

Is there a miss somewhere?

@fenollp
Copy link
Collaborator

fenollp commented Dec 30, 2022

Hi! Thanks for opening a pull request,
As you noted there, the solution is to DefineStringFormat("uuid", FormatOfStringForUUIDOfRFC4122) before validation.

The OpenAPI spec does not define the uuid format and so handling validation of it out of scope of this lib. Feel free to opt-in to the uuid validation mode though.

@fenollp fenollp closed this as completed Dec 30, 2022
@zekth
Copy link
Contributor Author

zekth commented Dec 30, 2022

Hi! Thanks for opening a pull request, As you noted there, the solution is to DefineStringFormat("uuid", FormatOfStringForUUIDOfRFC4122) before validation.

The OpenAPI spec does not define the uuid format and so handling validation of it out of scope of this lib. Feel free to opt-in to the uuid validation mode though.

So why having email and not uuid then?

@fenollp
Copy link
Collaborator

fenollp commented Dec 30, 2022

Indeed you're right, this is a mistake as old as the first commit! b855615#diff-90e14c30c1c7403690a666a976d821851020aa362bf984c3d7a6e8e0b2abcca4R22

Thanks for spotting this. I'd accept a PR that removes that line and mentions this change in the README for the next minor version bump.

@zekth
Copy link
Contributor Author

zekth commented Dec 30, 2022

This is technically a breaking change so having it in minor bump seems wrong. I'd personally leave it like so. Maybe refer this issue in the codebase for the email format definition.

@fenollp
Copy link
Collaborator

fenollp commented Dec 30, 2022

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.

2 participants