Skip to content
OBLAIDISH NEWS
Constantant's openapi-resource-gen trims Angular API bundles
TX_870502Engineering

Constantant's openapi-resource-gen trims Angular API bundles

Constantant's openapi-resource-gen, an Nx generator, creates typed InjectionTokens from OpenAPI specs for Angular 22+ projects, enabling file-level tree-shaking [DevTo][GitHub].

Constantant's openapi-resource-gen, an Nx generator, creates signal-native, per-endpoint InjectionTokens from an OpenAPI 3.x spec for Angular 22+ projects [DevTo]. The package ships as an npm devDependency (@constantant/openapi-resource-gen) and a matching mock library (@constantant/openapi-resource-mocks) [GitHub]. Running npx nx g @constantant/openapi-resource-gen:api-resource against a spec URL produces a directory tree where each endpoint lives in its own *.token.ts file, exports a typed InjectionToken, and provides a provideX() factory that returns an httpResource instance. Types are pulled directly from the generated schema.d.ts (produced by openapi-typescript), so no hand-written interfaces drift. Because Angular’s bundler (esbuild) drops entire files that are never imported, any token that isn’t injected disappears from the final bundle. In contrast, the three mainstream generators (OpenAPI Generator, NSwag, orval) emit a service class per tag; importing the class once pulls in all methods, even unused ones. openapi-resource-gen guarantees file-level tree-shaking out of the box [DevTo]. The mock library adds a DevTools panel that lets developers toggle loading, error, or custom responses for any token without rebuilding the app [GitHub]. It also supplies a mockResource helper for Vitest/Jasmine tests, enabling deterministic unit-test scenarios. The use of signals replaces RxJS boilerplate, cutting repetitive code by roughly 30% in typical CRUD components. Testing becomes more efficient with the built-in mock bus and Chrome DevTools UI, reducing the need for separate MSW handler files and speeding up end-to-end test iteration [DevTo].

operator_channel
[ comments_offline · provider_not_configured ]
transmission_log

Subscribe to the broadcast.

Daily digest of the day's most important tech news. No fluff. Engineering signal only.

// delivered via substack · double-opt-in confirmation