@archeion/swagger-angular-api is a collection of templates designed to be used with swagger-typescript-api. These templates facilitate the generation of Angular services from an OpenAPI specification, making it easier to integrate APIs into Angular applications.
To install the library, you can use npm or yarn:
npm install @archeion/swagger-angular-api swagger-typescript-apior
yarn add @archeion/swagger-angular-api swagger-typescript-apiThis library is not intended to be used standalone. Instead, you need to import the templates provided by this library into swagger-typescript-api to generate Angular services for your Swagger APIs.
Here's an example of how to use the templates with swagger-typescript-api:
const { generateApi } = require('swagger-typescript-api');
const path = require('path');
generateApi({
name: 'MyAPI',
output: path.resolve(__dirname, './src/app/api'),
url: 'https://your-api-spec-url.com/swagger.json',
templates: path.resolve(__dirname, './node_modules/@archeion/swagger-angular-api/templates/angular'),
// Currently only modular mode is supported.
modular: true,
// Optionally you can add options to personalize angular generation
angular: {
generateIndex: true,
},
hooks: {
// Don't forget to add onInit hook
onInit: initAngularTemplates
}
})
.then(() => {
console.log('Angular services generated successfully!');
})
.catch((err) => {
console.error('Error generating Angular services:', err);
});Or you can head over swagger-typescript-api documentation to find instruction for CLI options.
$ npx swagger-typescript-api --templates ./node_modules/@archeion/swagger-angular-api/templates/angular --modular <OTHER_OPTIONS_HERE>Any operation whose response declares a text/event-stream content type is generated as an SSE-backed method using ngx-sse-client instead of HttpClient, returning a properly typed Observable<T> that parses each event's data as JSON. This is automatic — no extra configuration is required.
If your OpenAPI spec contains such endpoints, install ngx-sse-client in your Angular application:
npm install ngx-sse-clientThis project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request with your changes.
Special thanks to the developers of swagger-typescript-api for their foundational work.