orval-labs / orval

orval is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats. 🍺
https://orval.dev
MIT License
3.18k stars 336 forks source link

Orval produces files with syntax error if `pattern` contains `*/` #1703

Closed DefCon-007 closed 1 week ago

DefCon-007 commented 1 week ago

What are the steps to reproduce this issue?

  1. Use the following schema to generate typescript client in say fetch
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API",
    "version": "1.0.0"
  },
  "paths": {
    "/example": {
      "get": {
        "summary": "Retrieve example data",
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Hello, World!",
                       "pattern": "^([a-zA-Z_][a-zA-Z0-9_-]*:)?([a-zA-Z_][a-zA-Z0-9_-]*/)?([a-zA-Z_][.a-zA-Z0-9_-]*)$"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

What happens?

Since the pattern has */ inside, the generated TS file has an error and cannot be used directly. It will not be compiled. The JSDoc will be generated as follows:

/** @pattern ^([a-zA-Z_][a-zA-Z0-9_-]*:)?([a-zA-Z_][a-zA-Z0-9_-]*/)?([a-zA-Z_][.a-zA-Z0-9_-]*)$ */

What were you expecting to happen?

Orval should properly escape the pattern in order to not produce a file with error. …

Any logs, error output, etc?

Any other comments?

What versions are you using?

System: OS: macOS 15.1 CPU: (14) arm64 Apple M3 Max Memory: 566.78 MB / 36.00 GB Shell: 5.9 - /bin/zsh