openapi-typescript
openapi-typescript copied to clipboard
Missing Types for Pattern, MaxLength, MinLength
Missing Type Definitions for Pattern, MaxLength, MinLength
When trying to validate an OpenAPI 3 specification that is using Patterns, MaxLength, and MinLength for string and other data types, I get type errors when trying to use the aforementioned properties. I'm using 42Crunch for security audit and validation of generated API specifications, and it complains about these being missing. In the short-term, I've used x-pattern
and the like, and then simply replace the text before writing the file programmatically. Obviously, that's not ideal, and is only a workaround in one specific use-case. If you're trying to validate a specification that has these supported properties, it will fail.
Paste full error message
Name | Version |
---|---|
openapi-typescript |
^2.0.0 |
Node.js | 21.5.0 |
OS + version | macOS Sonoma (14.4) |
Reproduction
You can reproduce this by defining an API request, response, or schema and using the following property:
someParamName:
type: string
example: Here is a sample
maxLength: 50
pattern: ^.{1,50}$
description: Sample Param Name
nullable: false
Expected result
Should not get type errors when using supported properties maxLength, minLength, and pattern.
Checklist
- [x] My OpenAPI schema passes the Redocly validator (
npx @redocly/cli@latest lint
) - [x] I’m willing to open a PR (see CONTRIBUTING.md)
Here's the TypeScript error as it occurs when using the SchemaObject
type
I have a couple questions:
- Is
2.x
the correct openapi-typescript version you’re using (not 6.x)? 6.x is recommended for OpenAPI 3 (which isn’t even supported below 5.x) -
type: string
will always generate into astring
type in TypeScript; there won’t be anymaxLength
property on a string. If you look at the generated output forsomeParamName
, What does it generate now? What is the expected TypeScript you would like it to generate?
This issue is stale because it has been open for 90 days with no activity. If there is no activity in the next 7 days, the issue will be closed.
This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.