Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

cblx/oang

Repository files navigation

oang

Angular library for helping writing UI components and validators based on Open Api Schemas:

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#schema-object

Demo:

https://cblxoang.z15.web.core.windows.net/

This library has 2 capabilities:

  1. Creates a FormGroup from an OpenApi schema with validations, default values and UI extra information.

  2. Provides a component that will resolve specific components based on the schema

Usage

Installing

npm install cblx.br/oang --save-dev

Import OangModule

import { OangMaterialModule } from '@cblx.br/oang';


@NgModule({
  imports: [
    OangModule,
  ]
})
export class MyModule { }

Creating FormGroups from OpenApi schemas

import { OangEngine } from '@cblx.br/oang';

@Component(...)
class MyComponent{
   formGroupInfo: FormGroupInfo;
   constructor(oangEngine: OangEngine){
   this.formGroupInfo = oangEngine.createForm(schemaCatalog /* the schema dictionary */, 'MyRequestDto' /* the schema object name */);
}

The formGroupInfo has the following fields of interest:

  • control: FormGroup
  • controlInfos: { [key:string]: ControlInfo }

A ControlInfo will be created for each property of the schema object