Tutorials

June 18, 2026 · View on GitHub

Step-by-step guides for @constantant/openapi-resource-gen and friends. Each guide builds on the previous one; if you're starting fresh, read them in order.

Prerequisites: Angular 22+, Nx 22+, an existing Angular application.


Guides

#GuideWhat you'll learn
1Setup — generate a data-access libInstall the generator, point it at a spec, understand what gets emitted
2Consuming tokens in componentsInject generated tokens, conditional requests, mutations, auth
3Unit tests with /testingDrop-in Vitest/Jasmine mocks, MockResourceHandle, response sequences
4E2E tests with PlaywrightFull mock bus, page.evaluate() control, history assertions
5Chrome DevTools ExtensionCatch mode, Respond tab, Scenarios, History inspector, local mocks

Quick-reference

# Install
npm install -D @constantant/openapi-resource-gen @constantant/openapi-resource-mocks

# Generate from a URL — no curl step needed
npx nx g @constantant/openapi-resource-gen:api-resource \
  --specPath=https://petstore3.swagger.io/api/v3/openapi.yaml \
  --outputDir=libs/petstore-data-access/src \
  --baseUrlToken=PETSTORE_BASE_URL \
  --includeMocks \
  --specId=petstore

# Unit test a component
import { mockResource } from '@constantant/openapi-resource-mocks/testing';
const petsMock = mockResource(FIND_PETS_BY_STATUS, { value: [] });
TestBed.configureTestingModule({ providers: [petsMock] });

# Control a mock from Playwright
await page.evaluate(() =>
  openApiMock('FIND_PETS_BY_STATUS').resolve([{ id: 1, name: 'Rex', status: 'available' }])
);