Skip to main content
Version: 3.1.0

Overview

The @abpjs/schematics package provides types, interfaces, and utilities for code generation in ABP React applications. This is the React equivalent of Angular's @abp/ng.schematics module.

npm version

Installation

npm install @abpjs/schematics
# or
yarn add @abpjs/schematics

Purpose

This package provides the foundational types and utilities needed for:

  • API Proxy Generation - Types for ABP API definition parsing
  • Code Generation - Models for generating services, methods, and interfaces
  • Type Mapping - .NET to TypeScript type conversion

Main Exports

API Definition Types

TypeDescription
ApiDefinitionRoot API definition with modules and types
ModuleModule definition with controllers
ControllerController with actions
ActionAPI endpoint definition
TypeType definition (classes, enums)
PropertyDefProperty within a type
ParameterInSignatureMethod signature parameter
ParameterInBodyHTTP request body parameter

Code Generation Models

ClassDescription
ServiceGenerated service representation
MethodMethod with signature and body
SignatureMethod signature definition
BodyMethod body with HTTP details
ModelModel file containing interfaces
InterfaceTypeScript interface definition
PropertyProperty within an interface
ImportImport statement

Enums

EnumDescription
eBindingSourceIdParameter binding source (Body, Path, Query, Model)
eMethodModifierMethod visibility (Public, Private, etc.)
eImportKeywordImport keywords (type, interface)

Constants

ConstantDescription
PROXY_PATHDefault path for generated proxy files
PROXY_CONFIG_PATHPath to proxy configuration JSON
PROXY_WARNINGWarning message for generated directory
SYSTEM_TYPESMap of .NET types to TypeScript types
ExceptionStandard error message templates

Configuration

TypeDescription
GenerateProxySchemaSchema for proxy generation options
ProxyConfigProxy configuration interface
ProjectProject definition for generation

Usage Examples

Working with API Definitions

import type { ApiDefinition, Module, Controller, Action } from '@abpjs/schematics';

function processApiDefinition(apiDef: ApiDefinition) {
// Iterate over modules
for (const [moduleName, module] of Object.entries(apiDef.modules)) {
console.log(`Module: ${moduleName}`);

// Iterate over controllers
for (const [controllerName, controller] of Object.entries(module.controllers)) {
console.log(` Controller: ${controller.controllerName}`);

// Iterate over actions
for (const [actionName, action] of Object.entries(controller.actions)) {
console.log(` Action: ${action.name} (${action.httpMethod} ${action.url})`);
}
}
}
}

Creating Service Models

import { Service, Method, Signature, Body } from '@abpjs/schematics';
import { eMethodModifier } from '@abpjs/schematics';

// Create a service
const service = new Service({
name: 'UserService',
namespace: 'MyApp.Users',
apiName: 'default',
});

// Create a method signature
const signature = new Signature({
name: 'getUsers',
modifier: eMethodModifier.Public,
returnType: 'Promise<UserDto[]>',
});

// Create a method body
const body = new Body({
method: 'GET',
url: '/api/users',
responseType: 'UserDto[]',
});

// Create the complete method
const method = new Method({ signature, body });
service.methods.push(method);

Type Mapping

import { SYSTEM_TYPES } from '@abpjs/schematics';

// Convert .NET type to TypeScript
function convertType(dotnetType: string): string {
return SYSTEM_TYPES.get(dotnetType) ?? 'unknown';
}

console.log(convertType('Int32')); // 'number'
console.log(convertType('String')); // 'string'
console.log(convertType('Guid')); // 'string'
console.log(convertType('Bool')); // 'boolean'

Parameter Binding

import { eBindingSourceId } from '@abpjs/schematics';
import type { ParameterInBody } from '@abpjs/schematics';

function describeParameter(param: ParameterInBody): string {
switch (param.bindingSourceId) {
case eBindingSourceId.Body:
return `${param.name} comes from request body`;
case eBindingSourceId.Path:
return `${param.name} comes from URL path`;
case eBindingSourceId.Query:
return `${param.name} comes from query string`;
case eBindingSourceId.Model:
return `${param.name} comes from model binding`;
default:
return `${param.name} has unknown source`;
}
}

Handling Errors

import { Exception } from '@abpjs/schematics';

function handleProxyError(error: string, moduleName: string) {
// Exception messages use {0}, {1} placeholders
const message = Exception.InvalidModule.replace('{0}', moduleName);
console.error(message);
// Output: [Invalid Module] Backend module "MyModule" does not exist in API definition.
}

See Also