Code generator to generate angular-specific typescript (model/service/validator) from an openapi-specification.
npm install @wtiben/openapi-typescript-angular-generatornpm install --save openapi-typescript-angular-generator.
npx openapi-typescript-angular-generator and following options:
-i file or URL of the openapi-specification
-o output destination for the generated code
-e (optional) building environment: java (default) or docker
-m (optional) mount root for the docker container
-a (optional) adds authorization headers when fetching the OpenAPI definitions
--additional-properties (optional) additional properties to pass to openapi-generator
Docker or Java must be installed for the generator to work.
/local.
FormControl-factory is generated. This factory can be used to create FormControl-instances:
// generated model
interface MyModel {
value: string;
}
namespace MyModel {
export enum Properties {
value = 'value',
}
}
// example data that could be fetched from a service
this.model: MyModel = { value: 'foobar' };
this.properties = MyModel.Properties;
this.errorMap = {
'prefix.value.required': 'Value is required',
};
// create a factory to create FormControls
const factory = new MyModel.FormControlFactory(model);
this.formGroup = new TypedFormGroup({
value: factory.createFormControl('value')
});
`
Now the created controls can be used at the view like this:
`
`
Only a single span is used to display errors for the field. Best usage is reached with