Zod validation plugin for ng-openapi - Generate Zod schemas from OpenAPI specifications
npm install @ng-openapi/zod
β‘Examples
β’
πDocumentation
β’
πIssues
tbd.
``bash`
npm install @ng-openapi/zod ng-openapi --save-dev
`typescript
// openapi.config.ts
import { GeneratorConfig } from 'ng-openapi';
import { HttpResourcePlugin } from '@ng-openapi/zod';
export default {
input: './swagger.json',
output: './src/api',
clientName: 'NgOpenApi',
plugins: [HttpResourcePlugin],
} as GeneratorConfig;
`
`bash`
ng-openapi -c openapi.config.ts
`typescript
// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideDefaultClient } from './api/providers';
export const appConfig: ApplicationConfig = {
providers: [
provideNgOpenApiClient({
basePath: 'https://api.example.com'
})
]
};
`
`typescript
import { Component, inject } from '@angular/core';
import { UsersResource } from './api/resources';
@Component({
selector: 'app-users',
template:
Loading...
Error: {{ users.error() }}
})
export class UsersComponent {
private readonly usersResource = inject(UsersResource);
// Automatic caching and reactive updates
readonly users = this.usersResource.getUsers();
}
`Generated Structure
`
src/api/
βββ models/ # TypeScript interfaces
βββ resources/ # HTTP Resource services
β βββ index.ts # Resource exports
β βββ *.resource.ts # Generated resources
βββ services/ # Traditional HttpClient services
βββ providers.ts # Provider functions
βββ index.ts # Main exports
``- π Full Documentation
- π Live Examples