Skip to content

feat: update action inputs #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ on:
branches:
- main
pull_request:
types:
- opened
- ready_for_review
- reopened
- synchronize

jobs:
upload:
Expand All @@ -26,14 +21,14 @@ jobs:
id: upload-json-openapi-spec
uses: ./
with:
api-key: ${{ secrets.HEY_API_TOKEN }}
dry-run: true
hey-api-token: ${{ secrets.HEY_API_TOKEN }}
path-to-openapi: ./openapi.json
path-to-file: ./openapi.json

- name: Upload YAML OpenAPI spec
id: upload-yaml-openapi-spec
uses: ./
with:
api-key: ${{ secrets.HEY_API_TOKEN }}
dry-run: true
hey-api-token: ${{ secrets.HEY_API_TOKEN }}
path-to-openapi: ./openapi.yaml
path-to-file: ./openapi.yaml
45 changes: 26 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<div align="center">
<img alt="Hey API logo" height="150" src="https://heyapi.dev/images/logo-300w.png" width="150">
<h1 align="center"><b>Upload OpenAPI Specification</b></h1>
<p align="center">🚀 A GitHub Action that uploads your OpenAPI specifications to Hey API</p>
<p align="center">🚀 A GitHub Action for uploading specifications to Hey API</p>
</div>

To use this action, you have to be registered with
[Hey API](https://heyapi.dev/). If you don't have an account, please
[email us](mailto:[email protected]) or
[open an issue](https://github.com/hey-api/upload-openapi-spec/issues) and we
will set you up.
> Before using this GitHub Action, you must create a free account with
> [Hey API](https://app.heyapi.dev/) and generate a project API key.

## Usage

Create a new GitHub workflow or add an upload step to your existing workflow
Create a new GitHub workflow or add an upload step to an existing workflow
inside your API codebase.

```yaml
Expand All @@ -22,6 +19,7 @@ on:
push:
branches:
- main
pull_request:

jobs:
upload-openapi-spec:
Expand All @@ -31,32 +29,41 @@ jobs:
uses: actions/checkout@v4

- name: Upload OpenAPI spec
uses: hey-api/upload-openapi-spec@v1
uses: hey-api/upload-openapi-spec@v1.2.0
with:
hey-api-token: ${{ secrets.HEY_API_TOKEN }}
path-to-openapi: path/to/openapi.json
api-key: ${{ secrets.HEY_API_TOKEN }}
path-to-file: path/to/openapi.json
tags: optional,custom,tags
```

The example above will send your OpenAPI spec to Hey API on every push to `main`
branch.
The example above will upload your OpenAPI specification to Hey API on every
pull request and push to the `main` branch.

## Inputs

To successfully upload an OpenAPI specification, you need to provide the
following inputs (see `with` in the example above)

### `hey-api-token`
### `api-key`

This is the authorization token you obtained from us.
This is the project API key you obtained from
[Hey API](https://app.heyapi.dev/).

### `path-to-openapi`
> Note: Personal API keys can't be used to upload specifications.

A relative path to your OpenAPI spec file within the repository. Note that you
might need an additional step in your GitHub workflow to generate this file (see
### `path-to-file`

A relative path to your OpenAPI file within the repository. Note that you might
need an additional step in your GitHub workflow to generate this file (see
[FastAPI example](https://fastapi.tiangolo.com/how-to/extending-openapi/#generate-the-openapi-schema)).

### `tags` (optional)

A comma-separated string value representing any custom tags you wish to add to
your OpenAPI specification.

## Next Steps

Please follow the
[integrations guide](https://heyapi.vercel.app/openapi-ts/integrations.html) on
our website for the next steps.
[integrations guide](https://heyapi.dev/openapi-ts/integrations) on our website
for the next steps.
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ branding:
icon: file-plus
description: Upload your OpenAPI specification to Hey API
inputs:
api-key:
description: Hey API service token
required: true
base-url:
description: Configure Hey API server URL
required: false
dry-run:
description: Run action in dry run mode
required: false
hey-api-token:
description: Hey API service token
required: true
path-to-openapi:
path-to-file:
description: Input path to your OpenAPI specification file
required: true
tags:
Expand Down
30 changes: 15 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ import { upload } from './upload'
*/
export async function run(): Promise<void> {
try {
const apiKey: string = core.getInput('api-key', {
required: true
})
const baseUrl: string = core.getInput('base-url', {
required: false
})
const dryRun: boolean =
core.getInput('dry-run', {
required: false
}) === 'true'
const baseUrl: string = core.getInput('base-url', {
required: false
})
const heyApiToken: string = core.getInput('hey-api-token', {
required: true
})
const pathToOpenApi: string = core.getInput('path-to-openapi', {
const pathToFile: string = core.getInput('path-to-file', {
required: true
})
const tags: string = core.getInput('tags', {
required: false
})

core.debug(`Path to OpenAPI: ${pathToOpenApi}`)
core.debug(`Path to OpenAPI: ${pathToFile}`)
core.debug(`Upload started: ${new Date().toTimeString()}`)
await upload({
apiKey,
baseUrl,
dryRun,
heyApiToken,
pathToOpenApi,
pathToFile,
tags
})
core.debug(`Upload completed: ${new Date().toTimeString()}`)
Expand Down
22 changes: 11 additions & 11 deletions src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import { postV1Specifications } from './client'
* Read and upload the provided OpenAPI specification to Hey API.
*/
export async function upload({
apiKey,
baseUrl,
dryRun,
heyApiToken,
pathToOpenApi,
pathToFile,
tags
}: {
/**
* Hey API token.
*/
apiKey: string
/**
* Custom service url.
*/
Expand All @@ -20,20 +24,16 @@ export async function upload({
* Return mock response?
*/
dryRun?: boolean
/**
* Hey API token.
*/
heyApiToken: string
/**
* Path to the OpenAPI specification file.
*/
pathToOpenApi: string
pathToFile: string
/**
* Custom specification tags.
*/
tags?: string
}): Promise<void> {
if (!pathToOpenApi) {
if (!pathToFile) {
throw new Error('invalid OpenAPI path')
}

Expand All @@ -51,15 +51,15 @@ export async function upload({
}
}

const specification = new Blob([fs.readFileSync(pathToOpenApi)], {
const specification = new Blob([fs.readFileSync(pathToFile)], {
type:
pathToOpenApi.endsWith('.yaml') || pathToOpenApi.endsWith('.yaml')
pathToFile.endsWith('.yaml') || pathToFile.endsWith('.yaml')
? 'application/yaml'
: 'application/json'
})

const { error } = await postV1Specifications({
auth: heyApiToken,
auth: apiKey,
baseUrl: baseUrl || 'https://api.heyapi.dev',
body: {
actor: process.env.GITHUB_ACTOR,
Expand Down