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

openapi-typescript-angular-generator

v13.0.0

Published

Code generator to generate angular-specific typescript (model/service/validator) from an openapi-specification.

Downloads

25

Readme

OpenAPI Angular Typescript Generator

This is a code generator to generate angular-specific typescript code from an OpenAPI-specification.

It's based on the OpenAPI Generator from OpenAPITools. As opposed to the OpenAPI Generator which just generates models and services, the OpenAPI Angular Typescript Generator also generates the according validators and FormControlFactories to use with Angular's Reactive Forms.

Usage

Install it with npm install --save openapi-typescript-angular-generator.

Code Generation

Run it with 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 remotely. Pass in a URL-encoded string of name:header with a comma separating multiple values
  • --additional-properties (optional) additional properties to pass to openapi-generator

Docker or Java must be installed for the generator to work.

Pay attention to the input/output-parameter when using docker. These parameters will be used after the docker container is started and the volume is mounted. So any path-resolution, except the input-parameter is an url, will be start from /local.

Proxy settings from the executed process will be applied to the openapi-generator-process.

Usage of custom FormGroup and FormControl with FormControl-factories

For each model a 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<MyModel>({
  value: factory.createFormControl<string>('value')
});

Now the created controls can be used at the view like this:

<form [formGroup]="formGroup">

  <input type="text" [formControlName]="properties.value"
        [required]="formGroup.isValidatorRegistered(properties.value, 'required')" />

  <!-- only a single error hint is necessary -->
  <span class="error" *ngIf="formGroup.hasControlErrors(properties.value)">
    <!-- prefix.value.required is returned, if error occurs -->
    {{ errorMap[formGroup.nextControlErrorKey(properties.value, 'prefix')] }}
  </span>

</form>

Only a single span is used to display errors for the field. Best usage is reached with <mat-error> tag from material.angular.io.

License

Copyright 2018 T-Systems Multimedia Solutions GmbH (https://www.t-systems-mms.com/) Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) Copyright 2018 SmartBear Software

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.