Skip to content

mysk/generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Forsyteco Generator

NestJS-hosted apibuilder code generator service for Forsyte API specs.

Generators

Key Output
forsyte_nestjs_dtos {app}-enums.ts, {app}-dtos.ts under generated/{application-key}/ (or src/generated/ in consumer repos)
forsyte_nestjs_controllers {app}-controllers.ts under generated/{application-key}/ (or src/generated/ in consumer repos)

Example for forsyte/address:

generated/address/
β”œβ”€β”€ address-enums.ts
β”œβ”€β”€ address-dtos.ts
└── address-controllers.ts

Example for forsyte/feature_flag:

generated/feature-flag/
β”œβ”€β”€ feature-flag-dtos.ts
└── feature-flag-controllers.ts

Local development

pnpm install
node test/fixtures/build-fixtures.mjs   # refresh fixtures from forsyteco-spec
pnpm start:dev                          # http://localhost:7050

Smoke test

curl http://localhost:7050/generators
curl -X POST http://localhost:7050/invocations/forsyte_nestjs_dtos \
  -H "Content-Type: application/json" \
  -d @test/fixtures/forms/address-invocation.json

Validation

pnpm validate:local    # build + offline spec validation; writes golden files to test-output/
pnpm validate:http     # requires pnpm start:dev

Golden snapshots under test-output/ are regenerated by pnpm validate:local and checked in CI.

Spec route and import conventions: see forsyteco-spec/CONVENTIONS.md.

Offline consumer generation (no server)

pnpm build
node scripts/write-consumer-generated.mjs /path/to/consumer-project address

Tests

node test/fixtures/build-fixtures.mjs
pnpm test:e2e

Register on apibuilder.io

Expose port 7050 (e.g. via ngrok), then:

curl -X POST https://api.apibuilder.io/generator_services \
  -H "Authorization: Bearer $APIBUILDER_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"uri": "https://<your-public-url>"}'

Generate from the UI or CLI:

apibuilder code forsyte address 0.0.1 forsyte_nestjs_dtos .

Generate into a consumer repo

Set GENERATED_OUTPUT_ROOT to the project root (not src/). Output lands in src/generated/:

# PowerShell
$env:GENERATED_OUTPUT_ROOT = "C:\Repos\forsyteco-data-gateway"
pnpm generate data_gateway
src/generated/
β”œβ”€β”€ data-gateway/
β”œβ”€β”€ error/
β”œβ”€β”€ healthcheck/
└── tsconfig.json

Hand-written API integration

import { AddressesController as AddressesControllerTrait } from "@/generated/address/address-controllers";

@UseGuards(JwtAuthGuard, IsOrganisationGuard)
export class AddressesController extends AddressesControllerTrait {
  constructor(private readonly service: AddressesService) {
    super();
  }

  findOne(organisationIdOrSlug: string, addressId: string): Promise<AddressDto> {
    return this.service.getAddressById(addressId, organisationIdOrSlug, organisationIdOrSlug);
  }
}

About

NestJS apibuilder code generators πŸ€–

Resources

Stars

Watchers

Forks

Releases

No releases published

Contributors