feat(global): add OpenAPI definition and Axios custom user agent magic

Also we updated package.json to include repository object for use in the lib/userAgent.js file.

Signed-off-by: Andrei Jiroh Eugenio Halili <ajhalili2006@gmail.com>
This commit is contained in:
Andrei Jiroh Halili 2022-04-28 12:11:26 +00:00
parent 7c022093a9
commit c25539aae5
4 changed files with 77 additions and 0 deletions

8
lib/userAgent.js Normal file
View File

@ -0,0 +1,8 @@
module.exports = () => {
if (!process.env.USER_AGENT_HTTP_CLIENT) {
const { name, version, repository }= require("../package.json")
return `${name}@${version}, ${repository.url}`
} else {
return process.env.USER_AGENT_HTTP_CLIENT
}
}

View File

@ -3,6 +3,10 @@
"author": "Andrei Jiroh Halili <ajhlili2006@gmail.com>",
"version": "0.1.0",
"license": "MIT",
"repository": {
"url": "https://gitlab.com/RecapTime/infra/rtapp-verify-backend-autocode",
"type": "git"
},
"publish": false,
"scripts": {
"start": "lib http",

8
scripts/update-oas-wiki.js Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env node
const { readFileSync } = require('fs');
const axios = require("axios")
const apiBase = axios.todo;
var yamlData = readFileSync("./www/openapi.yaml", 'utf8')
var encodedData = encodeURIComponent(yamlData)
console.log("URL-encoded YAML data:", encodedData)

57
www/openapi.yaml Normal file
View File

@ -0,0 +1,57 @@
# SPDX-LICENSE: MIT
#<syntaxhighlight lang="yaml">
openapi: 3.0.3
info:
title: Verification Endpoint API
termsOfService: https://policy.recaptime.eu.org/api-terms
version: doc 0.1.0
servers:
- url: https://dev--rtapp-verify-backend.recaptime.autocode.gg
description: development
- url: https://rtapp-verify-backend.recaptime.autocode.gg
description: production
tags:
- name: meta
- name: Index Lookup
- name: Requires Authentication
- name: OAuth
- name: Webhooks
- name: Admin-only / Debug
components:
securitySchemes:
bearerToken:
type: http
scheme: bearer
paths:
/ping/:
get:
summary: Pings Autocode servers whenever the deployment is up.
tags:
- meta
responses:
200:
description: Everything is up.
content:
application/json:
schema:
type: object
properties:
ok:
type: boolean
example: true
ping:
type: string
example: "Pong!"
/lookup/me/:
get:
security:
- bearerToken: []
summary: Query yourself based on current authenticated user.
tags:
- Requires Authentication
- Index Lookup
/oauth/mediawiki/:
get:
summary: |
Endpoint used by integration bots built by Recap Time Squad for
#</syntaxhighlight>