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-openapi-forms

v1.0.0

Published

Generates Angular Reactive-driven forms as multiply files from open-api YAML or JSON.

Downloads

2

Readme

Build Status

This is an npm-cli library that allows you to generate Angular Reactive Forms for models from the Open-Api 3.0 description.

Installation

  1. Run npm i ngx-openapi-forms --save-dev in terminal

Usage

  1. In terminal type ngx-openapi-forms --input <path-to-openapi-file> --output <output-dir-path>. All params are required.
  2. The lib will parse your open-api file than create one file per top-level model of "object" type in the description.
  3. The created model.ts file will contain Angular FormGroup with FormControls and FormArrays (exported as default) from the open-api model, including validation and default values.

Important note

You should import a deep copy of the generated FormGroup object to avoid unexpected behavior. For expample, use cloneDeep method from lodash

Example

OpenApi entities:

IPet:
  type: object
  properties:
    id:
      type: string
      format: uuid
      readOnly: true
    kind:
      type: string
  required:
    - kind

Cat:
  allOf:
    - $ref: "#/components/schemas/IPet"
    - type: object
      properties:
        tail:
          type: boolean
          default: true
        name:
          type: string
          pattern: "^[a-zA-Z]&"
      required:
        - tail
        - name
    
Dog:
  allOf:
    - $ref: "#/components/schemas/IPet"
    - type: object
      properties:
        tail:
          type: boolean
          default: true
        barks:
          type: boolean
          default: true
        name:
          type: string
          pattern: "^[a-zA-Z]&"
          default: "Bob"
      required:
        - tail
        - name
    
Fish:
  allOf:
    - $ref: "#/components/schemas/IPet"
    - type: object
      properties:
        color:
          type: string
      required:
        - color    
    
IAquariumLook:
  type: object
  properties:
    shape:
      type: string
      default: "round"
    background:
      type: string
      default: "transparent"
          
IAquariumProps:
  type: object
  properties:
    fishes:
      type: array
      items:
        $ref: "#/components/schemas/Fish"
      lights:
        type: number
        minimum: 1
        maximum: 5

Fishes:
  type: array
  items:
    $ref: "#/components/schemas/Fish"
    
Aquarium:
  type: object
  allOf:
    - $ref: "#/components/schemas/IAquariumLook"
    - $ref: "#/components/schemas/IAquariumProps"
    - type: object
      properties:
        foo:
          type: string
          default: "baz"

The lib will generate Reactive forms for Cat, Dog, Fish and Aquarium openapi-models. PlainProperty is not a FormGroup, IPet, IAquariumLook and IAquariumProps are interfaces or abstract classes.

Examples of generated multiply files:

/* tslint:disable */
/* eslint-disable */
import { FormGroup, FormControl, FormArray, Validators } from '@angular/forms';

const cat = new FormGroup({
  id: new FormControl(
    {
      value: null,
      disabled: true,
    },
    []
  ),
  kind: new FormControl(
    {
      value: null,
      disabled: false,
    },
    [Validators.required]
  ),
  tail: new FormControl(
    {
      value: true,
      disabled: false,
    },
    [Validators.required]
  ),
  name: new FormControl(
    {
      value: null,
      disabled: false,
    },
    [Validators.pattern(/^[a-zA-Z]&/), Validators.required]
  ),
});

export default cat;
/* tslint:disable */
/* eslint-disable */
import { FormGroup, FormControl, FormArray, Validators } from '@angular/forms';

const aquarium = new FormGroup({
  shape: new FormControl(
    {
      value: 'round',
      disabled: false,
    },
    []
  ),
  background: new FormControl(
    {
      value: 'transparent',
      disabled: false,
    },
    []
  ),
  fishes: new FormArray([]),
  lights: new FormControl(
    {
      value: null,
      disabled: false,
    },
    [Validators.min(1), Validators.max(5)]
  ),
  foo: new FormControl(
    {
      value: 'baz',
      disabled: false,
    },
    []
  ),
});

export default aquarium;