Skip to content
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

fix: add api key type per operation #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const isBeta = pathItemOperation.title.includes('[BETA]')
<OperationDescription operation={pathItemOperation} {schema} />
<Md text={operation.description} />
<ExternalDocs docs={operation.externalDocs} />
<Authorizations />
<Authorizations {schema} />
<Parameters operation={pathItemOperation} />
<RequestBody {operation} {schema} />
<Responses {operation} responses={operation.responses} {schema} />
Original file line number Diff line number Diff line change
@@ -1,16 +1,49 @@
---
import type { Schema } from '../../libs/schema'
import Key from '../Key.astro'

interface Props {
schema: Schema
}

interface KeyInfo {
name: string
private: boolean
}

const { schema } = Astro.props

// allowlist of openapi files and key types.
const keyInfoPerFile: Record<string, KeyInfo> = {
'openapi/v1.yml': {
name: 'Marketplace',
private: false,
},
'openapi/v2.yml': {
name: 'Marketplace',
private: false,
},
'openapi/cs.yml': {
name: 'Advanced',
private: true,
},
}

const key = keyInfoPerFile[schema.config.schema]
if (key === undefined) {
throw new Error(`unknown openapi file ${schema.config.schema}`)
}
---

<div>
<h3>Authentication</h3>

<p>
Topsort’s APIs are authenticated via bearer tokens. Requests must include an authorization header containing your
private API key.
The Topsort API uses bearer tokens for authentication. Requests must include an authorization header containing a
valid API key as a token.
</p>

<p>Don't have an API key yet? <a href="/api/authentication">Learn how to generate one</a>.</p>
<p>Don't have API key(s) yet? <a href="/api/authentication">Learn how to generate them</a>.</p>

<div class="sl-oa-schema">
<details class="root" open={true}>
Expand All @@ -21,9 +54,20 @@ import Key from '../Key.astro'
</div>

<div>
<p>The header containing a private API key. Format this header as follows:</p>

<p><code>Authorization: Bearer &lt;YOUR-API-KEY&gt;</code></p>
<p>
Header containing your <strong>{key.name} API key</strong> as a token.
{
key.private ? (
<span>
<strong>This key is confidential, use it server-side only.</strong>
</span>
) : (
<span>This key is public, use it on both client and server.</span>
)
}
</p>
<p>Header format:</p>
<p><code>Authorization: Bearer &lt;YOUR-{key.name.toUpperCase()}-API-KEY&gt;</code></p>
</div>
</Key>
</details>
Expand Down