Skip to content

Commit

Permalink
feat: change name to swagger-api-hub
Browse files Browse the repository at this point in the history
  • Loading branch information
shijistar committed May 3, 2024
1 parent d2fe275 commit 38f735c
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 122,125 deletions.
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,
});
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

### Features

- add commitlint ([fba1adf](https://github.com/shijistar/api-hub/commit/fba1adfc3d440c7b5b2c24eb2514053ae8d4556b))
- add husky and lint-staged ([d58e331](https://github.com/shijistar/api-hub/commit/d58e3318e48df67dcbe63df4e9287d810d531bae))
- add main implementation of api-hub ([63af1d3](https://github.com/shijistar/api-hub/commit/63af1d3b545d1f403928067130d3db7b077561ad))
- 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.

Expand All @@ -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[] = [
{
Expand All @@ -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.
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 38f735c

Please sign in to comment.