Skip to content

Conversation

@Himenon
Copy link
Owner

@Himenon Himenon commented Nov 9, 2021

Summary

  • Add option to convert Schema with format to any type definition.

related issues

Design

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;
}

@Himenon Himenon merged commit 24c7bd2 into main Nov 9, 2021
@Himenon Himenon deleted the feat/convert-option branch November 9, 2021 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: PDFをダウンロードするAPIの型

2 participants