Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: shijistar/swagger-api-hub
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 37c71fc1a934ad901c6de7da68bc145e2d12817d
Choose a base ref
...
head repository: shijistar/swagger-api-hub
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.0
Choose a head ref
  • 3 commits
  • 16 files changed
  • 1 contributor

Commits on May 3, 2024

  1. Copy the full SHA
    9bc1c7e View commit details
  2. feat: add commitlint

    shijistar committed May 3, 2024
    Copy the full SHA
    d2fe275 View commit details
  3. Copy the full SHA
    38f735c View commit details
Showing with 1,218 additions and 122,168 deletions.
  1. +10 −0 .fatherrc.ts
  2. +9 −0 .husky/commit-msg
  3. +12 −0 .husky/pre-commit
  4. +2 −32 .prettierignore
  5. +2 −4 .prettierrc
  6. +5 −3 CHANGELOG.md
  7. +14 −14 README.md
  8. +0 −122,092 api-spec.json
  9. +5 −3 bin/{api-hub.js → swagger-api-hub.js}
  10. +1 −1 cli/paths.ts
  11. +2 −2 cli/repl.ts
  12. +4 −0 commitlint.config.js
  13. +20 −7 package.json
  14. +1,129 −6 pnpm-lock.yaml
  15. +2 −3 api-hub.config.ts → sample/swagger-api-hub.config.ts
  16. +1 −1 tsconfig.json
10 changes: 10 additions & 0 deletions .fatherrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'father';

export default defineConfig({
cjs: {
input: 'cli',
output: 'lib',
platform: 'node',
},
sourcemap: true,
});
9 changes: 9 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env sh

. "$(dirname "$0")/_/husky.sh"

echo "\033[36m Linting commit messages... \033[0m"
sleep 0.5

npx commitlint --edit $1

12 changes: 12 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

echo "\033[36m Linting code... \033[0m"

npx --no-install lint-staged

sleep 0.3
echo "\033[32m Linting passed! \033[0m"
echo

sleep 1
34 changes: 2 additions & 32 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,43 +1,13 @@
.umi
.umi-production
**/src/umi
node_modules
dist
lib
.dockerignore
.DS_Store
.eslintignore
*.png
*.toml
docker
.editorconfig
Dockerfile*
.gitignore
.prettierignore
.prettierrc.json
LICENSE
.eslintcache
*.lock
yarn-error.log
.history
CNAME
/modules
build
public
CHANGELOG.md
**/*.less.d.ts
packages/*/dist
packages/*/build
packages/*/public
packages/*/src/api/*/**/*
packages/gdcd/es
packages/gdcd/lib
packages/gdcd/dist
packages/gdcd/_site
packages/gdcd-pro/packages/*/es
packages/gdcd-pro/packages/*/lib
packages/gdcc/es
packages/gdcc/lib
packages/gdcb/es
packages/gdcb/lib

iconfont.js
pnpm-lock.yaml
6 changes: 2 additions & 4 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -29,15 +29,13 @@
"importOrderSortSpecifiers": true,
"importOrderGroupNamespaceSpecifiers": true,
"importOrderCaseInsensitive": true,
"jsdocParser": true,
"jsdocSingleLineComment": false,
"jsdocSeparateReturnsFromParam": true,
"jsdocSeparateTagGroups": true,
"jsdocCapitalizeDescription": false,
"jsdocPrintWidth": 60,
"jsdocPrintWidth": 80,
"overrides": [
{
"files": [".prettierrc", ".eslintrc", ".babelrc"],
"files": [".prettierrc", ".eslintrc"],
"options": {
"parser": "json"
}
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
- ## 0.1.0
# 1.0.0-alpha.0 (2024-05-02)

2024-04-29
### Features

- 🆕 The first release
- add commitlint ([fba1adf](https://github.com/shijistar/swagger-api-hub/commit/fba1adfc3d440c7b5b2c24eb2514053ae8d4556b))
- add husky and lint-staged ([d58e331](https://github.com/shijistar/swagger-api-hub/commit/d58e3318e48df67dcbe63df4e9287d810d531bae))
- add main implementation of swagger-api-hub ([63af1d3](https://github.com/shijistar/swagger-api-hub/commit/63af1d3b545d1f403928067130d3db7b077561ad))
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# api-hub
# swagger-api-hub

Produce front-end interface code for OpenAPI-based backend services with a single click. This tool is designed to generate TypeScript code for API clients and request methods from OpenAPI specifications. It can be used as a command line tool or as a Node.js module which is integrated into your build process. It supports both OpenAPI 2.0 and 3.0 specifications.

@@ -10,34 +10,34 @@ This tool is a wrapper of the [swagger-typescript-api
**Install as global command line tool:**

```bash
$ npm install -g api-hub
$ npm install -g swagger-api-hub
```

**Install as project-wide dependency:**

```bash
$ npm install -D api-hub
$ npm install -D swagger-api-hub
```

## Usage

#### Use as global command line tool:

It reads the default configuration file `./api-hub.config.ts`, you can also specify a custom configuration file.
It reads the default configuration file `./swagger-api-hub.config.ts`, you can also specify a custom configuration file.

```bash
$ api-hub
$ api-hub config/services.ts
$ swagger-api-hub
$ swagger-api-hub config/services.ts
```

The configuration file should export an array of `ServiceConfig` objects. If you export only one object, it will generate the code directly without prompting. The config file extension can be `.ts`, `.js`, `.json`, or any other module types supported by Node.js.

The file should look like this:

_api-hub.config.ts_
_swagger-api-hub.config.ts_

```typescript
import type { ServiceConfig } from 'api-hub';
import type { ServiceConfig } from 'swagger-api-hub';

const services: ServiceConfig[] = [
{
@@ -59,10 +59,10 @@ export default services;

The `ServiceConfig` object has the following properties:

- `id`: *[required]* A unique identifier for the service.
- `id`: _[required]_ A unique identifier for the service.
- `name`: A human-readable name for the service.
- `url`: *[required]* The URL of the OpenAPI specification file. If you have a local file, you can use `input` instead of `url` to specify the file path. Or you can even use `spec` to provide the OpenAPI specification object directly. Either `url`, `input`, or `spec` is required.
- `apiBase`: The base path of all API endpoints. The service may be hosted on a subpath of the main domain, e.g., */public-api/iam/v3*, then the apiBase is */public-api* in this case. If the original api path from the OpenAPI specification is acceptable, you don't need this field.
- `url`: _[required]_ The URL of the OpenAPI specification file. If you have a local file, you can use `input` instead of `url` to specify the file path. Or you can even use `spec` to provide the OpenAPI specification object directly. Either `url`, `input`, or `spec` is required.
- `apiBase`: The base path of all API endpoints. The service may be hosted on a subpath of the main domain, e.g., _/public-api/iam/v3_, then the apiBase is _/public-api_ in this case. If the original api path from the OpenAPI specification is acceptable, you don't need this field.
- `crossOrigin`: Whether to use the absolute api path when calling the service. This is useful when the service is hosted on a different domain and you need to set the `Access-Control-Allow-Origin` header. Default is `false`.
- `output`: The output directory for the generated code. The default is `./src/api/{id}`.
- `httpClientFile`: Change the default path of `http-client.ts` file, so you can use your own http client. The default is `./http-client` under each service directory.
@@ -72,9 +72,9 @@ The `ServiceConfig` object has the following properties:
#### Use as npm dependency:

```typescript
import { generate, promptToGenerate } from 'api-hub';
import type { ServiceConfig } from 'api-hub';
import services from './api-hub.config';
import { generate, promptToGenerate } from 'swagger-api-hub';
import type { ServiceConfig } from 'swagger-api-hub';
import services from './swagger-api-hub.config';

// Way1: Generate multiple services with prompts
promptToGenerate(services);
Loading