Skip to content

Commit

Permalink
feat: add OpenAPI schema (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostrider-05 authored Oct 28, 2024
1 parent ddf065f commit bb335e7
Show file tree
Hide file tree
Showing 72 changed files with 5,147 additions and 985 deletions.
6 changes: 5 additions & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ github:
- changed-files:
- any-glob-to-any-file:
- '.github/*'
- '.github/**'
- '.github/**'
openapi:
- changed-files:
- any-glob-to-any-file:
- 'openapi.json'
20 changes: 20 additions & 0 deletions .github/workflows/openapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: OpenAPI
on:
workflow_dispatch:
push:
paths:
- '**/schemas/v2/api'
- '**/schemas/v2/resources'
- '**/scripts/v2/openapi'
branches: main
jobs:
update:
name: Update specs
runs-on: ubuntu-latest
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.PAT }}
repository: ghostrider-05/patreon-api-spec
event-type: spec_update
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,3 @@ dist

# Test file for example
example.ts

# Generated by scripts
src/schemas/v2/generated
23 changes: 19 additions & 4 deletions apps/worker-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,33 @@ import {
Type,
} from 'patreon-api.ts'

import routes from './routes'
interface LibraryData {
version: number
base: string
headers: {
userAgent: string
response: Record<'id' | 'sha', string>
}

import type { LibraryData } from '../../../docs/.vitepress/components/data'
relationships: Record<string, {
resourceKey: string;
includeKey: string;
isArray: boolean;
isRelated: boolean;
}[]>
schemas: Record<string, string[] | readonly string[]>
webhook: {
triggers: string[]
}
}

export default <ExportedHandler>{
async fetch(request) {
const { pathname } = new URL(request.url)

const corsHeaders = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,HEAD,POST,OPTIONS',
'Access-Control-Allow-Methods': 'DELETE,GET,HEAD,POST,PATCH,OPTIONS',
'Access-Control-Max-Age': '86400',
}

Expand All @@ -34,7 +50,6 @@ export default <ExportedHandler>{
sha: PATREON_RESPONSE_HEADERS.Sha,
}
},
routes,
schemas: {
...Object.keys(SchemaKeys).reduce((obj, key) => ({ ...obj, [key.toLowerCase()]: SchemaKeys[key] }), {}),
[Type.PledgeEvent]: SchemaKeys.PledgeEvent,
Expand Down
98 changes: 0 additions & 98 deletions apps/worker-docs/src/routes.ts

This file was deleted.

62 changes: 62 additions & 0 deletions docs/.vitepress/components/GitHubStat.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { VPLink } from 'vitepress/theme'
const stat = ref(0)
const props = defineProps<{
repo: string
keyName: string
iconClass: string
label: string
}>()
onMounted(async () => {
const res = await fetch('https://api.github.com/repos/' + props.repo)
.then(res => res.json() as Promise<Record<string, number>>)
.then(res => res[props.keyName])
if (res) stat.value = res
})
</script>

<template>
<p>
<VPLink :href="'https://github.com/' + repo"><span :class="iconClass"></span> {{ stat }} {{ label }}</VPLink>
</p>
</template>

<style scoped>
.VPNavScreenMenu p {
margin-top: 20px;
}
p {
display: flex;
align-items: center;
justify-content: center;
}
a:hover {
cursor: pointer;
}
a {
line-height: 20px;
border-radius: 3px;
padding: 0px 4px;
background-color: var(--vp-c-bg-soft);
color: var(--vp-c-brand-1) !important;
display: flex;
align-items: center;
justify-content: center;
}
a span {
background-color: var(--vp-c-white);
border-color: var(--vp-c-white);
width: 20px !important;
height: 20px !important;
margin: 5px;
}
</style>
17 changes: 12 additions & 5 deletions docs/.vitepress/components/LibraryTable.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<script setup lang="ts">
const greenColor = 'green'
const redColor = 'red'
const greenColor = 'var(--vp-c-green-3)'
const redColor = 'var(--vp-c-red-3)'
const officialText = 'Official'
function getColor (key, value) {
interface Key {
id: string
name: string
title: string
colors?: 'boolean' | Record<number, 'green' | 'red'>
}
function getColor (key: Key, value: number | boolean) {
if (!key.colors) return undefined
else if (key.colors === 'boolean') return value === true ? greenColor : redColor
else return { red: redColor, green: greenColor }[key.colors[value]]
else return { red: redColor, green: greenColor }[key.colors[<number>value]]
}
function getStyle (key, value) {
function getStyle (key: Key, value: number | boolean) {
const color = getColor(key, value)
if (color) return { backgroundColor: color, color: 'var(--vp-c-neutral-inverse)', textAlign: 'center' }
else return {}
Expand Down
Loading

0 comments on commit bb335e7

Please sign in to comment.