Releases: Himenon/openapi-typescript-code-generator
Releases · Himenon/openapi-typescript-code-generator
@himenon/[email protected]
@himenon/[email protected]
- update docs #42
@himenon/[email protected]
@himenon/[email protected]
- Add
allowOperationIds
option #40
@himenon/[email protected]
BREAKING_CHANGE
Deprecated API
- generateTypeScriptCode
New API
- CodeGenerator Class
Features
- Code Generator's API has been classed to allow procedural code generation #31
- Multiple code templates can be set in the generator #34
- Enables direct retrieval of parameters extracted from OpenAPI #35
- Code Template also accepts
string
in addition to the return value ofts.statement[]
.
Migration
Basic usage
Before
import { generateTypeScriptCode } from "@himenon/openapi-typescript-code-generator";
const code = generateTypeScriptCode({
entryPoint,
log: {
validator: {
displayLogLines: 1,
},
},
});
After
import { CodeGenerator } from "@himenon/openapi-typescript-code-generator";
import * as Templates from "@himenon/openapi-typescript-code-generator/templates";
import type * as Types from "@himenon/openapi-typescript-code-generator/types";
const codeGenerator = new CodeGenerator(entryPoint);
codeGenerator.validateOpenApiSchema({ logger: { displayLogLines: 1 } });
const apiClientGeneratorTemplate: Types.CodeGenerator.CustomGenerator<Templates.ApiClient.Option> = {
generator: Templates.ApiClient.generator,
option: {},
};
const code = codeGenerator.generateTypeDefinition([
codeGenerator.getAdditionalTypeDefinitionCustomCodeGenerator(),
apiClientGeneratorTemplate,
]);
For rewriteCodeAfterTypeDeclaration
user
Before
import { generateTypeScriptCode } from "@himenon/openapi-typescript-code-generator";
const code = generateTypeScriptCode({
entryPoint,
option: {
rewriteCodeAfterTypeDeclaration: (context, codeGeneratorParamsList) => {
/** awesome code */
return [];
},
},
});
After
import { CodeGenerator } from "@himenon/openapi-typescript-code-generator";
import * as Templates from "@himenon/openapi-typescript-code-generator/templates";
import type * as Types from "@himenon/openapi-typescript-code-generator/types";
const codeGenerator = new CodeGenerator(entryPoint);
const apiClientGeneratorTemplate: Types.CodeGenerator.CustomGenerator<Templates.ApiClient.Option> = {
generator: Templates.ApiClient.generator,
option: {},
};
const code = codeGenerator.generateTypeDefinition([
codeGenerator.getAdditionalTypeDefinitionCustomCodeGenerator(),
apiClientGeneratorTemplate,
{
generator: () => {
/** awesome code */ // <------------ here!
return [];
},
}
]);
@himenon/[email protected]
Features
- Support dual package #27
@himenon/[email protected]
@himenon/[email protected]
- Added an option to output API Client with synchronous functions #22
@himenon/[email protected]
New Features
- Add
allowOperationIds
option. - Add ErrorResponse Type Declaration.