Skip to content

Commit

Permalink
[IDP-1845] Add documentation (#17)
Browse files Browse the repository at this point in the history
* temp

* temp

* temp

* [IDP-1845] Add documentation

* PRC
  • Loading branch information
tjosepo authored Jul 18, 2024
1 parent 1e8fd46 commit 3e24b26
Show file tree
Hide file tree
Showing 19 changed files with 630 additions and 1 deletion.
35 changes: 35 additions & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish Docs

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
build:
runs-on: ubuntu-latest

permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

steps:
- uses: actions/checkout@v4

- name: Build with Retype
uses: retypeapp/action-build@latest
id: retype
with:
config: docs/retype.yaml
license: ${{ secrets.RETYPE_API_KEY }}

- name: Upload Retype artifact
uses: actions/upload-artifact@v2
with:
name: github-pages
path: ${{ steps.retype.outputs.retype-output-path }}

- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ yarn-error.log*
.idea

# project
dist
dist

# retype
retype.manifest
11 changes: 11 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "docs",
"private": true,
"scripts": {
"dev": "retype start",
"build": "retype build"
},
"dependencies": {
"retypeapp": "3.5.0"
}
}
34 changes: 34 additions & 0 deletions docs/retype.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -------------------
# Retype
# -------------------

poweredByRetype: false

input: ./src
output: ./dist

url: https://gsoft-inc.github.io/wl-openapi-typescript/

branding:
title: OpenAPI TS
logo: ./resources/logo.png

favicon: ./resources/favicon.png

edit:
repo: https://github.com/gsoft-inc/wl-openapi-typescript
base: ./apps/docs/src
branch: main

footer:
copyright: "© Copyright {{ year }} - Workleap"

toc:
depth: 2

hub:
link: https://gsoft-inc.github.io/wl-idp-docs-hub/
alt: Workleap's IDP homepage

start:
pro: true
1 change: 1 addition & 0 deletions docs/src/_includes/head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link href="https://gsoft-inc.github.io/wl-idp-docs-hub/static/retype-customization.css" rel="stylesheet" />
1 change: 1 addition & 0 deletions docs/src/api/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
expanded: true
30 changes: 30 additions & 0 deletions docs/src/cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
icon: terminal
label: CLI
order: -2
---

# Command Line Interface

### `create-schemas`

#### Usage

```bash
create-schemas [input]
```

#### Options

Options passed to the CLI will always take precedence over options declared in
the config file.

| Options | Description |
|-|-|
| `-v, --version` | Display version number |
| `-c, --config <file>` | Use specified config file (default: `"create-schemas.config"`) |
| `-i, --input <path>` | Path to the OpenAPI schema file |
| `-o, --outdir <path>` | Output directory (default: `"./dist"`) |
| `--cwd <path>` | Path to working directory (default: `"."`) |
| `--watch` | Enable watch mode |
| `-h, --help` | Display available CLI options |
69 changes: 69 additions & 0 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
icon: gear
label: Configuration
order: -3
---

When running `create-schemas` from the command line, it will automatically try
to resolve a config file named `create-schemas.config.ts` inside project root
(other JS and TS extensions are also supported).

The most basic config file looks like this:

```ts create-schemas.config.ts
export default {
// config options
}
```

You can use the `defineConfig` helper which should provide intellisense:

```ts create-schemas.config.ts
import { defineConfig } from '@workleap/create-schemas'

export default defineConfig({
// example
})
```

## root
- **Type:** `string`
- **Default:** `process.cwd()`

Project root directory used to resolve relative paths. Can be an absolute path, or a path relative to the current working directory.

## input
- **Type:** `string`

Path to the OpenAPI schema file. Can be a local path or URL to a remote file.

## outdir
- **Type:** `string`
- **Default:** `"./dist"`

Output directory path. The files that will be generated in this directory
depends on the plugins being used.

## watch
- **Type:** `boolean`
- **Default:** `false`

Enable watch mode. Watch mode will regenerate the code whenever the input file
or the configuration file changes.

## plugins
- **Type:** `Plugin[]`
- **Default:** `[]`

Array of plugins to use. See [Using Plugins](./using-plugins) for more details.

## openApiTsOptions

- **Type:** `OpenApiTsOptions`
- **Default:** `{}`


Options passed to OpenAPI TypeScript for type generation. You normally should
not have to change them.

[!ref target="blank" text="See OpenAPI TypeScript options"](https://openapi-ts.pages.dev/cli#flags)
93 changes: 93 additions & 0 deletions docs/src/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
icon: rocket
label: Getting Started
order: -1
---

# Getting Started

In your project, you can install the `create-schemas` CLI using:

+++ pnpm
```bash
pnpm add @workleap/create-schemas
```
+++ npm
```bash
npm install @workleap/create-schemas
```
+++ yarn
```bash
yarn add @workleap/create-schemas
```
+++

Create a `create-schemas.config.ts` file this this:

```js create-schemas.config.ts
import { defineConfig } from "@workleap/create-schemas";

export default defineConfig({
input: "https://petstore3.swagger.io/api/v3/openapi.json", // replace with your own OpenAPI schema
output: "src/codegen/schema.ts",
});
```

Then, run the `create-schemas` CLI in your terminal:

+++ pnpm
```bash
pnpm create-schemas
```
+++ npm
```bash
npx create-schemas
```
+++ yarn
```bash
yarn create-schemas
```
+++

The `src/codegen/schema.ts` file should be created.

## Watch mode

During development, you can regenerate the types whenever your input file
changes or configuration changes.

To enable watch mode, add the `--watch` flag to the CLI command or add `watch:
true` to the configuration file.

+++ pnpm
```bash
pnpm create-schemas --watch
```
+++ npm
```bash
npx create-schemas --watch
```
+++ yarn
```bash
yarn create-schemas --watch
```
+++

or

```js create-schemas.config.ts
import { defineConfig } from "@workleap/create-schemas";

export default defineConfig({
input: "./openapi.json",
watch: true,
});
```

## Advanced usage

If you have a more complex use case that isn't supported by
`@workleap/create-schemas` you can try extending the behavior of the library by
[Creating a Plugin](./using-plugins#creating-a-plugin) or using the [JavaScript API](./javascript-api).

If you think many users would benefit from a use case being officially supported, we encourage you to [open an issue on Github](https://github.com/gsoft-inc/wl-openapi-typescript/issues).
2 changes: 2 additions & 0 deletions docs/src/guide/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
icon: book
expanded: true
12 changes: 12 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
icon: home
label: Home
---

`@workleap/create-schemas` is a library for generating client code from OpenAPI Specifications.

### Start here

If you've never used this library before, here’s the best place to start:

[!ref Getting Started](./getting-started)
Loading

0 comments on commit 3e24b26

Please sign in to comment.