0.6.0 β€’ Published 4 months ago

initapi v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Features

  • Code as Document
  • Standardized, unified team style, easy to maintain
  • Tool generates code to reduce coding and improve efficiency
  • If the backend uses Swagger or Openapi3 specifications, it can be accessed at zero cost

Install

pnpm i initapi -D

Usage

configure api.config.ts or api.config.js

import { defineConfig } from "initapi";
// you can use the `defineConfig` helper which should provide intellisense without the need for jsdoc annotations:
export default defineConfig({
  // Path related configurations are all based on the working directory of the nodejs process
  // Supports Openapi3 and Swagger specifications, with content created based on specified JSON
  service: {
    pets: {
      url: "https://petstore.swagger.io/v2/swagger.json",
    },
    platform: {
      url: "http://127.0.0.1:3000/api-json",
      commonPrefix: "/api/v1",
    },
    // Can convert local JSON
    local: {
      url: "./assets/openapi.json",
      // API address public prefix, used to generate class names and file names. When not configured, it will automatically attempt to find the public prefix
      commonPrefix: "/mg/api",
    },
  },
  outputDir: "./src/api",
  outputType: "TypeScript",
  // ...
});
// package.json
"scripts": {
  "api": "initapi create"
}
pnpm run api

Generate API Workflows Example

Generate API Workflows Example

Generate API content example

Generate API content example

Generate Type content example

Generate Type content example

Configure

Detailed configuration items for defineConfig

NameDescriptionTypeRequiredDefault
importRequestImport axios or axios encapsulationstringNo'import axios from "axios";'
useRequestUsing axiosstringNo'axios.request'
serviceThe JSON (swagger/openapi3specification) file address corresponding to the API serviceobjectYesβ€”
outputDirOutput file storage locationstringNo'./api'
outputTypeOutput File Type - When there is no configuration, a command line interaction will pop up for selectionTypeScript or JavaScriptNoβ€”
definitionHow to define typesclass or interfaceNointerface
indexableThe advantage of using index signature is that it can add any number of attributes, making interface or class more flexible; The disadvantage is that it may cause uncertainty in the value type of the attributebooleanNofalse
enumModeHow to define enumeration (enum: generate enumeration type. type: generate type alias.)enum or typeNotype
multipleFilesEnable multi file mode - single file only creates API files. Multiple files will split the API into all controllers and generate corresponding filesbooleanNotrue

Prettier

Before creating a file, by default, the data will be formatted using a prettier

When the project root directory has a. prettier file, the default configuration will be used for file formatting. If obtaining the file fails, the built-in prettier will be used to format the default configuration:

const defaultOptions: prettier.Options = {
  parser: "typescript",
  printWidth: 130,
  tabWidth: 2,
  useTabs: false,
  semi: true,
  singleQuote: false,
  quoteProps: "as-needed",
  jsxSingleQuote: false,
  trailingComma: "all",
  bracketSpacing: true,
  bracketSameLine: true,
  jsxBracketSameLine: true,
  arrowParens: "avoid",
  rangeStart: 0,
  rangeEnd: Infinity,
  requirePragma: false,
  insertPragma: false,
  proseWrap: "preserve",
  htmlWhitespaceSensitivity: "ignore",
  endOfLine: "auto",
}

Git commit

  • πŸ’ test: Adding missing tests
  • 🎸 feat: A new feature
  • πŸ› fix: A bug fix
  • πŸ€– chore: Build process or auxiliary tool changes
  • ✏️ docs: Documentation only changes
  • πŸ’‘ refactor: A code change that neither fixes a bug or adds a feature
  • πŸ’„ style: Markup, white-space, formatting, missing semi-colons...
  • 🎑 ci: CI related changes
  • ⚑️ perf: A code change that improves performance

Last

Welcome to provide feedback and contribute code.

License

MIT

0.6.0

4 months ago

0.5.0

5 months ago

0.4.0

6 months ago

0.1.0-beta.3

11 months ago

0.1.0

11 months ago

0.3.0

10 months ago

0.1.2

10 months ago

0.0.3

12 months ago

0.2.0

10 months ago

0.0.2

12 months ago

0.0.4

12 months ago

0.0.1

1 year ago

0.0.1-beta.2

1 year ago

0.0.1-beta.1

1 year ago

0.0.1-beta.0

1 year ago

0.0.4-alpha

1 year ago

0.0.3-alpha

1 year ago

0.0.2-alpha

1 year ago

0.0.1-alpha

1 year ago

0.0.0-alpha

1 year ago

1.0.0

2 years ago