Generates an Angular ReactiveForm from a Swagger or OpenAPI definition.
Validation rules should have a single source of truth. These rules should be exposed to consumers to apply them. By doing this we can be sure that the same rules for UI validation are enforced at the API layer.
import{loadSpec,makeForm,saveFile}from'@verizonconnect/ngx-form-generator';asyncfunctionmain(){constspec=awaitloadSpec('swagger.json');constform=makeForm(spec);awaitsaveFile(form,'projects/forms/src/lib/index.ts');}awaitmain();import{FormGroup,FormControl,Validators}from'@angular/forms';exportconstaddressModelForm=newFormGroup({firstName:newFormControl(null,[Validators.required,Validators.pattern(/^[a-zA-Z\'\s]+$/),Validators.minLength(1),Validators.maxLength(100)]),lastName:newFormControl(null,[Validators.required,Validators.pattern(/^[a-zA-Z\'\s]+$/),Validators.minLength(1),Validators.maxLength(100)]),address:newFormControl(null,[Validators.required,Validators.pattern(/^[\w\'\s]+$/),Validators.minLength(1),Validators.maxLength(100)]),address2:newFormControl(null,[Validators.pattern(/^[\w\'\s]+$/),Validators.minLength(1),Validators.maxLength(100)]),city:newFormControl(null,[Validators.required,Validators.pattern(/^[\w\'\s]+$/),Validators.minLength(1),Validators.maxLength(100)]),postalCode:newFormControl(null,[Validators.required,Validators.pattern(/^[\w\s]+$/),Validators.minLength(4),Validators.maxLength(8)]),emailAddress:newFormControl(null,[Validators.required,Validators.pattern(/^[\w\@\!\#\%\&\'\*\+\-\/\=\?\`\{\|\}\~\.]+$/),Validators.email])});