thiagobustamante / typescript-rest-swagger

Swagger tools for typescript-rest
156 stars 56 forks source link

Describe min/max lengths for string types #50

Open dpkshrma opened 6 years ago

dpkshrma commented 6 years ago

The swagger spec allows for specifying minimum and maximum length of string keys. Reference - https://swagger.io/docs/specification/data-models/data-types/#string

I could not find any documentation on how to describe them in the types for request body.

AFAIK, Typescript does not support length checks out of the box for string data type. Is there a specific syntax to achieve this?

dpkshrma commented 6 years ago

Also, I can see that this BaseSchema interface in this file - https://github.com/thiagobustamante/typescript-rest-swagger/blob/master/src/swagger/swagger.ts does contain minLength specification.

I still don't understand how to declare in my own interfaces for the request body.

@thiagobustamante Please suggest a way to do it.

dpkshrma commented 6 years ago

Okay. I was looking at getSwaggerTypeForPrimitiveType method in https://github.com/thiagobustamante/typescript-rest-swagger/blob/master/src/swagger/generator.ts

And it seems there is no such option available yet. But, I might hopefully be wrong :|

d-theo commented 5 years ago

I have a similar question with pattern for strings to specify a regex👍