openapi-typescript-code-generator

TypeScript code generator via OpenAPI scheme.

MIT License

Downloads
11.8K
Stars
196
Committers
9

Bot releases are hidden (Show)

openapi-typescript-code-generator -

Published by Himenon almost 3 years ago

Features

Goooood News!!! Data Types including format are now supported !!!!

  • feat: Support for schema containing format #63

Input Schema

components:
  schemas:
    Binary:
      type: string
      format: binary
    IntOrString:
      type: string
      format: int-or-string
    AandB:
      type: string
      format: A-and-B

Generator Option

import { CodeGenerator, Option } from "@himenon/openapi-typescript-code-generator";
const option: Option = {
  convertOption: {
    formatConversions: [
      {
        selector: {
          format: "binary",
        },
        output: {
          type: ["Blob"],
        },
      },
      {
        selector: {
          format: "int-or-string",
        },
        output: {
          type: ["number", "string"],
        },
      },
      {
        selector: {
          format: "A-and-B",
        },
        output: {
          type: ["A", "B"],
          multiType: "allOf",
        },
      },
    ],
  },
};
const codeGenerator = new CodeGenerator(inputFilename, option);

Output

export namespace Schemas {
    export type Binary = Blob;
    export type IntOrString = number | string;
    export type AandB = A & B;
}
openapi-typescript-code-generator -

Published by Himenon almost 3 years ago

openapi-typescript-code-generator -

Published by Himenon almost 3 years ago

Bug Fix

  • feat: support nullable field of combine schemas (#61)
openapi-typescript-code-generator -

Published by Himenon about 3 years ago

Features

  • feat: support property access via reference object #59

New support schema

$ref: "#/components/schemas/Book/properties/author"
openapi-typescript-code-generator -

Published by Himenon about 3 years ago

  • fix: Fixed the logic for deleting duplicate TypeAlias #58
openapi-typescript-code-generator -

Published by Himenon about 3 years ago

Bug Fix

  • fix: schema added support for cases where schemas name contains '.' #57

New Support Schema

components:
  schemas:
    Book.Author:   # OK
      type: object
      properties:
        name:
          type: string
openapi-typescript-code-generator -

Published by Himenon about 3 years ago

Update

  • #56
openapi-typescript-code-generator -

Published by Himenon about 3 years ago

Improved stability

  • fix: Trim the trailing slash of baesUrl #55
openapi-typescript-code-generator -

Published by Himenon over 3 years ago

Bug Fix

  • Required condition of Parameter Object (@keita1714 in #53 )
openapi-typescript-code-generator -

Published by Himenon over 3 years ago

openapi-typescript-code-generator -

Published by Himenon over 3 years ago

  • Fix #47 #48
openapi-typescript-code-generator -

Published by Himenon over 3 years ago

  • update docs #42
openapi-typescript-code-generator -

Published by Himenon over 3 years ago

openapi-typescript-code-generator -

Published by Himenon over 3 years ago

  • Add allowOperationIds option #40
openapi-typescript-code-generator -

Published by Himenon over 3 years ago

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 of ts.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 [];
    },
  }
]);
openapi-typescript-code-generator - @himenon/[email protected]

Published by Himenon over 3 years ago

Features

  • Support dual package #27
openapi-typescript-code-generator -

Published by Himenon over 3 years ago

  • Support for windows #24 #26
openapi-typescript-code-generator -

Published by Himenon over 3 years ago

  • Added an option to output API Client with synchronous functions #22
openapi-typescript-code-generator -

Published by Himenon over 3 years ago

New Features

  • Add allowOperationIds option.
  • Add ErrorResponse Type Declaration.
openapi-typescript-code-generator -

Published by Himenon over 3 years ago

  • #19