Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Generate Angular ReactiveForms from OpenAPI documents

License

NotificationsYou must be signed in to change notification settings

verizonconnect/ngx-form-generator

Repository files navigation

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.

Commitizen friendly

Install

# install locally in projectnpm install @verizonconnect/ngx-form-generator --save-dev# install globallynpm install @verizonconnect/ngx-form-generator -g

CLI Usage

ngx-form-generator -f swagger.json -o projects/forms/src/lib/# when installed locally in project run with npxnpx ngx-form-generator -f swagger.yaml -o projects/forms/src/lib/
OptionAliasCommentRequired
--versionShow version number
--input-spec-i, --swaggerUrlLocation of the OpenAPI spec as URL or file path
--output-o, --outDirWhere to write the generated files
--file-name-f, --outFileGenerated file name
--help-hShow help

Example CLI Usage

ngx-form-generator -i https://petstore.swagger.io/v2/swagger.json -o petstore-formsngx-form-generator -i https://petstore.swagger.io/v2/swagger.yaml -o petstore-formsnpx ngx-form-generator -i swagger.json -o project/form/src/lib

Library Usage

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();

Examples Generated Form

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])});

License

MIT


[8]ページ先頭

©2009-2025 Movatter.jp