npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-form-generator-openapi

v1.0.0

Published

Generates an Angular ReactiveForm from a Swagger or OpenAPI definition

Downloads

138

Readme

Angular Form Generator

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 project
npm install @robertrudnicki/ngx-form-generator --save-dev

# install globally
npm install @robertrudnicki/ngx-form-generator -g

CLI Usage

ngx-form-generator -f swagger.json -o projects/forms/src/lib/

# when installed locally in project run with npx
npx ngx-form-generator -f swagger.yaml -o projects/forms/src/lib/

| Option | Alias | Comment | Required | | ------------ | ---------------- | ------------------------------------------------ | -------- | | --version | | Show version number | | | --input-spec | -i, --swaggerUrl | Location of the OpenAPI spec as URL or file path | ✓ | | --output | -o, --outDir | Where to write the generated files | | | --file-name | -f, --outFile | Generated file name | | | --help | -h | Show help | |

Example CLI Usage

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

Library Usage

import { loadSpec, makeForm, saveFile } from '@robertrudnicki/ngx-form-generator';

async function main() {
  const spec = await loadSpec('swagger.json');
  const form = makeForm(spec);
  await saveFile(form, 'projects/forms/src/lib/index.ts');
}
await main();

Examples Generated Form

import { FormGroup, FormControl, Validators } from '@angular/forms';

export const addressModelForm = new FormGroup({
  firstName: new FormControl(null, [
    Validators.required,
    Validators.pattern(/^[a-zA-Z\'\s]+$/),
    Validators.minLength(1),
    Validators.maxLength(100)
  ]),
  lastName: new FormControl(null, [
    Validators.required,
    Validators.pattern(/^[a-zA-Z\'\s]+$/),
    Validators.minLength(1),
    Validators.maxLength(100)
  ]),
  address: new FormControl(null, [
    Validators.required,
    Validators.pattern(/^[\w\'\s]+$/),
    Validators.minLength(1),
    Validators.maxLength(100)
  ]),
  address2: new FormControl(null, [
    Validators.pattern(/^[\w\'\s]+$/),
    Validators.minLength(1),
    Validators.maxLength(100)
  ]),
  city: new FormControl(null, [
    Validators.required,
    Validators.pattern(/^[\w\'\s]+$/),
    Validators.minLength(1),
    Validators.maxLength(100)
  ]),
  postalCode: new FormControl(null, [
    Validators.required,
    Validators.pattern(/^[\w\s]+$/),
    Validators.minLength(4),
    Validators.maxLength(8)
  ]),
  emailAddress: new FormControl(null, [
    Validators.required,
    Validators.pattern(/^[\w\@\!\#\%\&\'\*\+\-\/\=\?\`\{\|\}\~\.]+$/),
    Validators.email
  ])
});

License

MIT