Skip to content

Gen: Pattern with Format Makes Validation Always Fail #1504

@Unverified

Description

@Unverified

What version of ogen are you using?

github.com/ogen-go/ogen v1.14.0

Can this issue be reproduced with the latest version?

Yes

What did you do?

For snippet calling the client

openapi: 3.0.3
info:
  title: service
  description: Sample backend service
  version: 1.0.0
components:
  schemas:
    GenerateKeyRequestInput:
      type: object
      properties:
        encryptionKeyId:
          type: string
      required:
        - encryptionKeyId
    GenerateKeyResponse:
      type: object
      properties:
        encryptionKeyId:
          type: string
        privateKey:
          type: string
          format: base64
          pattern: ^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$
      required:
        - encryptionKeyId
        - privateKey
      additionalProperties: false
paths:
  /genkey:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/GenerateKeyRequestInput"
      responses:
        "200":
          description: Default Response
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/GenerateKeyResponse"
        default:
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  name:
                    type: string
                  message:
                    type: string
                required:
                  - name
                  - message
                additionalProperties: false

Calling the service with some input returns the following:

{
  "encryptionKeyId": "6d4cc1ae-3cd5-491b-9b60-53335a05fd1d",
  "privateKey": "bXJrLTAwMmIwOTE4MzZhMzRkY2FiZjU3OWM3MDNlMjNlMmVmOM4S9O1Q031IOv95lVj0O+swrsjoD1BO0AwSIQwyaTe8MQuGz/gMtriVeVcWjys7XaNy2Th7Vfw+qUzJPwn8Gj565nUD1wWKnEp+CYM02NlUIS72egYWmr9t4N+7x/aV3oxYtm6XPDJZRvYoTdco8A=="
}

(nothing here is confidential even if it might look like it, its just some throwaway values)

What did you expect to see?

That the call would succeed properly populating the go object.

What did you see instead?

error returned,

decode response: validate: invalid: privateKey (string: no regex match: ^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions