I use swagger-codegen to generate an API for typescript-angular2.
The Swagger JSON file contains as well additional information. e.g. minLength, maxLength of a string:
"AppointmentViewModel": {
"required": [
"Title"
],
"type": "object",
"properties": {
"Id": {
"format": "int32",
"type": "integer"
},
"Ansprechpartner": {
"maxLength": 100,
"minLength": 0,
"type": "string"
},
Issue: I cannot find this information (minLength,maxLength) in the generated code. Does swagger-coden for typescript-angular2 not support this or do is miss something?
2.2.3
java -jar ./swagger-codegen-cli-2.2.3.jar generate -i http://example.ch/swagger/docs/v1 -l typescript-angular2 -o ./src/api -DsupportES6=true -DmodelPropertyNaming=original
Generate code with additional information like minLength, maxLength.
@nextremos looks like it's not support at the moment.
The model templates for TS Angular2 can be found in https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angular/modelGeneric.mustache
For Ruby and other generators, we've added the support of various validation rules already:
Would you have time to help adding something similar to TS Angular2 model template?
@wing328 I have no experience with mustache files nor with the codegen - will need some time to experiment. I wonder what the outcome should be - maybe you could give me an advice? The minLenght/maxLenght should be part of the model, or should it be separated somehow?
I find this a bit problematic: in Angular we cannot just create restriction annotations in models. Angular supports two validation variants: model- and template-driven. In template driven validation the validation rules are written in the html-template and in model/reactive-driven is rules are implemented programmatically in a Component (or another class). See the following Plunkr. I believe it should/could be possible to create such directives and form controls... Need to think about it a bit longer.
cc @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx
It would be nice to integrate validation using class-validator
Any progress in this? Or do you have some manual how to work with mustache files?
Most helpful comment
It would be nice to integrate validation using class-validator