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

Missing Types for Pattern, MaxLength, MinLength #1594

Open
2 tasks done
joshuamil opened this issue Mar 19, 2024 · 2 comments
Open
2 tasks done

Missing Types for Pattern, MaxLength, MinLength #1594

joshuamil opened this issue Mar 19, 2024 · 2 comments
Labels
openapi-ts Relevant to the openapi-typescript library question Further information is requested

Comments

@joshuamil
Copy link

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

@joshuamil joshuamil added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Mar 19, 2024
@joshuamil
Copy link
Author

Here's the TypeScript error as it occurs when using the SchemaObject type
image

@drwpow
Copy link
Owner

drwpow commented Mar 19, 2024

I have a couple questions:

  1. 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)
  2. type: string will always generate into a string type in TypeScript; there won’t be any maxLength property on a string. If you look at the generated output for someParamName, What does it generate now? What is the expected TypeScript you would like it to generate?

@drwpow drwpow added question Further information is requested and removed bug Something isn't working labels Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openapi-ts Relevant to the openapi-typescript library question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants