
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
@getflip/error-code-generator
Advanced tools
A library to extract error codes from an open api spec and generate error codes types and objects for TypeScript and Dart.
Error Code Generator is a TypeScript library aimed at simplifying the process of managing and generating error codes in a systematic manner across different programming languages in your projects. This allows you to create, manage, and implement error codes efficiently, ensuring coherent error management throughout your applications. Define the error codes in your OpenAPI specification, and the library will generate the associated code in the languages of your choice.
Ensure to import the main class and the relevant factory for a seamless integration:
import {
ErrorCodeGenerator,
CodeGeneratorHandler,
} from "@getflip/error-code-generator";
ErrorCodeGenerator is the pivotal class responsible for orchestrating the
error code generation process. This class coordinates with various handlers,
ensuring a systematic workflow from extracting error codes to generating the
associated TypeScript code and writing them to files.
Initialization:
Instantiate the ErrorCodeGenerator with an array of code generators:
const generator = new ErrorCodeGenerator(codeGenerators);
Where codeGenerators contains instances of code generators, such as
TypeScript or Dart generators. The codeGenerators array can be created
through the CodeGeneratorFactory. There are two languages supported at the
moment: TypeScript and Dart.
const codeGenerators = [
CodeGeneratorFactory.createGenerator("TypeScript"),
CodeGeneratorFactory.createGenerator("Dart"),
];
// or
const generator = new ErrorCodeGenerator([
CodeGeneratorFactory.createGenerator("TypeScript"),
CodeGeneratorFactory.createGenerator("Dart"),
]);
Configuration: The Error Code Generator requires a few configurations to be set before running the generation process. These configurations are:
Set the source path:
generator.setSourcePath("[your-openapi-spec-source-path]");
Set the output directory:
generator.setOutputDirectory("[your-output-directory]");
Optionally, add more code generators, in case you need additional languages:
generator.addCodeGenerators(additionalCodeGenerators);
Generate Error Codes:
Kickstart the error code generation process by invoking:
generator.generate();
Ensure all mandatory configurations are set before invoking the generate
method. Otherwise, an error will be thrown indicating the absence of
necessary configurations.
The Error Code Generator library supports TypeScript and Dart code generation
out of the box through the TypeScriptCodeGenerator and DartCodeGenerator
classes. However, the library is designed to be extensible, allowing you to add
support for additional languages. To add support for a new language, you need to
create a new class that implements the CodeGenerator interface. The interface
contains a single method, generate, which takes in an array of ErrorCode
objects and returns a string containing the generated code.
CodeGeneratorFactory: A factory to instantiate and manage various code generators, facilitating easy extension to support additional languages in the future.
CodeGenerator: An interface that defines the contract for code generators.
The interface contains a single method, generate, which takes in an array of
ErrorCode objects and returns a string containing the generated code.
export interface CodeGenerator {
language: string;
fileExtension: string;
generateCode(): GeneratedCode;
setEndpointErrorCollection(
errorCollection: EndpointErrorCollection,
): CodeGenerator;
}
The following example demonstrates how to use the Error Code Generator library. As it is build with the help of the Builder pattern, you can chain the methods to set the configurations and generate the error codes.
const generator = new ErrorCodeGenerator([
CodeGeneratorFactory.createGenerator("TypeScript"),
CodeGeneratorFactory.createGenerator("Dart"),
])
.setSourcePath("[your-openapi-spec-source-path]")
.setOutputDirectory("[your-output-directory]")
.generate();
Ensure to replace placeholders such as [your-source-path] and
[your-output-directory] with actual paths relevant to your project.
Extend and customize ErrorCodeGenerator and associated handlers to accommodate
any project-specific requirements. Any contributions, feature requests, and
issue tracking are welcome! To get started with contributing, please refer to
our contribution guide.
To develop locally, run yarn, then yarn dev generate -s {source-yaml} -o {output-folder}.
This library is licensed under [Your License Name]. For more details, see the LICENSE file in the repository.
Feel free to modify documentation according to any specific features or nuances of the library, providing accurate links, paths, and guidelines for developers and users.
FAQs
A library to extract error codes from an open api spec and generate error codes types and objects for TypeScript and Dart.
The npm package @getflip/error-code-generator receives a total of 101 weekly downloads. As such, @getflip/error-code-generator popularity was classified as not popular.
We found that @getflip/error-code-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.