Swagger-codegen: Swagger Codegen does not generate validation information for typescript-angular2

Created on 31 Aug 2017  路  6Comments  路  Source: swagger-api/swagger-codegen

Description

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?

Swagger-codegen version

2.2.3

Command line used for generation

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

Steps to reproduce

Generate code with additional information like minLength, maxLength.

TypeScript Feature help wanted

Most helpful comment

It would be nice to integrate validation using class-validator

All 6 comments

@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:

https://github.com/swagger-api/swagger-codegen/blob/7bbe3dcb53e849f6be809a99ef93b82851dd9a9e/modules/swagger-codegen/src/main/resources/ruby/partial_model_generic.mustache#L87-L99

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?

Was this page helpful?
0 / 5 - 0 ratings