-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move docs to apps & top-level clean-up
- Loading branch information
1 parent
6fedbba
commit 532ff6e
Showing
137 changed files
with
257 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@intake24/docs", | ||
"type": "module", | ||
"version": "2024.8", | ||
"private": true, | ||
"description": "Intake24 documentation", | ||
"license": "Apache-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/MRC-Epid-it24/intake24.git", | ||
"directory": "apps/docs" | ||
}, | ||
"scripts": { | ||
"dev": "pnpm open-api && vitepress dev", | ||
"build": "pnpm open-api && vitepress build", | ||
"serve": "pnpm open-api && vitepress serve", | ||
"open-api": "pnpm tsx scripts/open-api.ts" | ||
}, | ||
"devDependencies": { | ||
"@ts-rest/open-api": "^3.51.0", | ||
"@types/node": "^22.10.2", | ||
"typescript": "^5.7.2", | ||
"vitepress": "^1.5.0" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import { writeFileSync } from 'node:fs'; | ||
import { resolve } from 'node:path'; | ||
|
||
import { generateOpenApi } from '@ts-rest/open-api'; | ||
|
||
import contract from '@intake24/common/contracts'; | ||
|
||
import pkg from '../package.json'; | ||
|
||
const defaultRecall = { | ||
type: 'object', | ||
properties: { | ||
preMeals: { type: 'array', items: [] }, | ||
meals: { type: 'object', properties: { | ||
preFoods: { type: 'array', items: [] }, | ||
foods: { type: 'array', items: [] }, | ||
postFoods: { type: 'array', items: [] }, | ||
} }, | ||
postMeals: { type: 'array', items: [] }, | ||
submission: { type: 'array', items: [] }, | ||
}, | ||
}; | ||
|
||
async function main() { | ||
const document = generateOpenApi(contract, { | ||
info: { | ||
title: 'Intake24 API Reference', | ||
description: pkg.description, | ||
license: { | ||
name: pkg.license, | ||
url: 'https://opensource.org/license/apache-2-0', | ||
}, | ||
version: pkg.version, | ||
}, | ||
servers: [ | ||
{ | ||
url: 'https://api.example.com', | ||
description: 'Intake24 API instance', | ||
}, | ||
], | ||
components: { | ||
securitySchemes: { | ||
bearerHttpAuthentication: { | ||
description: 'Bearer token using a JWT', | ||
type: 'http', | ||
scheme: 'Bearer', | ||
bearerFormat: 'JWT', | ||
}, | ||
}, | ||
}, | ||
}, { | ||
operationMapper: (operation, appRoute) => { | ||
/* | ||
* !!! TEMP HACKY REMOVAL OF HUGE RECALL SURVEY SCHEME OPEN API JSON SCHEME !!! | ||
* - size of the open-api json file grows from ~15MB to ~150MB, which is due to survey scheme recall JSON schema | ||
* - TODO: figure out how to maybe use JSON $refs with @ts-rest/open-api ? | ||
*/ | ||
if (appRoute.path === '/surveys/:slug/parameters') { | ||
operation.responses['200'].content['application/json'].schema.properties.surveyScheme.properties.prompts = { ...defaultRecall }; | ||
return operation; | ||
} | ||
|
||
if ( | ||
appRoute.path === '/admin/survey-schemes' | ||
|| appRoute.path === '/admin/survey-schemes/:surveySchemeId' | ||
|| appRoute.path === '/admin/survey-schemes/:surveySchemeId/edit' | ||
|| appRoute.path === '/admin/survey-schemes/:surveySchemeId/copy' | ||
|| appRoute.path === '/admin/survey-schemes/:surveySchemeId/templates' | ||
) { | ||
if (operation.requestBody?.content['application/json']?.schema?.properties?.prompts) | ||
operation.requestBody.content['application/json'].schema.properties.prompts = { ...defaultRecall }; | ||
|
||
if (operation.responses['200']?.content['application/json'].schema?.properties?.data) | ||
operation.responses['200'].content['application/json'].schema.properties.data = { type: 'array' }; | ||
if (operation.responses['200']?.content['application/json'].schema?.properties?.prompts) | ||
operation.responses['200'].content['application/json'].schema.properties.prompts = { ...defaultRecall }; | ||
if (operation.responses['201']?.content['application/json'].schema?.properties?.prompts) | ||
operation.responses['201'].content['application/json'].schema.properties.prompts = { ...defaultRecall }; | ||
|
||
return operation; | ||
} | ||
|
||
if ( | ||
appRoute.path === '/admin/survey-scheme-prompts' | ||
|| appRoute.path === '/admin/survey-scheme-prompts/:surveySchemePromptId' | ||
|| appRoute.path === '/admin/survey-scheme-prompts/:surveySchemePromptId/edit' | ||
|| appRoute.path === '/admin/survey-scheme-prompts/:surveySchemePromptId/sync' | ||
) { | ||
if (operation.requestBody?.content['application/json']?.schema?.properties?.prompt) | ||
operation.requestBody.content['application/json'].schema.properties.prompt = { type: 'object' }; | ||
|
||
if (operation.responses['200']?.content['application/json'].schema?.properties?.data) | ||
operation.responses['200'].content['application/json'].schema.properties.data = { type: 'array' }; | ||
if (operation.responses['200']?.content['application/json'].schema?.properties?.prompt) | ||
operation.responses['200'].content['application/json'].schema.properties.prompt = { type: 'object' }; | ||
if (operation.responses['201']?.content['application/json'].schema?.properties?.prompt) | ||
operation.responses['201'].content['application/json'].schema.properties.prompt = { type: 'object' }; | ||
|
||
return operation; | ||
} | ||
|
||
if ( | ||
appRoute.path === '/admin/surveys' | ||
|| appRoute.path === '/admin/surveys/:surveyId' | ||
|| appRoute.path === '/admin/surveys/:surveyId/edit' | ||
) { | ||
if (operation.requestBody?.content['application/json']?.schema?.properties?.surveySchemeOverrides?.properties?.prompts) | ||
operation.requestBody.content['application/json'].schema.properties.surveySchemeOverrides.properties.prompts = { type: 'array' }; | ||
|
||
if (operation.responses['200']?.content['application/json'].schema?.properties?.surveySchemeOverrides?.properties?.prompts) | ||
operation.responses['200'].content['application/json'].schema.properties.surveySchemeOverrides.properties.prompts = { type: 'array' }; | ||
if (operation.responses['201']?.content['application/json'].schema?.properties?.surveySchemeOverrides?.properties?.prompts) | ||
operation.responses['201'].content['application/json'].schema.properties.surveySchemeOverrides.properties.prompts = { type: 'array' }; | ||
|
||
if (operation.responses['200']?.content['application/json'].schema?.properties?.surveyScheme?.properties?.prompts) | ||
operation.responses['200'].content['application/json'].schema.properties.surveyScheme.properties.prompts = { ...defaultRecall }; | ||
if (operation.responses['201']?.content['application/json'].schema?.properties?.surveyScheme?.properties?.prompts) | ||
operation.responses['201'].content['application/json'].schema.properties.surveyScheme.properties.prompts = { ...defaultRecall }; | ||
|
||
return operation; | ||
} | ||
|
||
if (appRoute.path === '/admin/survey-schemes/refs') { | ||
if (operation.responses['200']?.content['application/json'].schema?.properties?.templates) | ||
operation.responses['200'].content['application/json'].schema.properties.templates = { type: 'array' }; | ||
|
||
return operation; | ||
} | ||
|
||
if (appRoute.path === '/admin/survey-scheme-prompts/refs') { | ||
if (operation.responses['200']?.content['application/json'].schema?.properties?.schemes) | ||
operation.responses['200'].content['application/json'].schema.properties.schemes = { type: 'array' }; | ||
|
||
return operation; | ||
} | ||
|
||
if (appRoute.path === '/admin/references/survey-schemes') { | ||
if (operation.responses['200']?.content['application/json'].schema?.properties?.data) | ||
operation.responses['200'].content['application/json'].schema.properties.data = { type: 'array' }; | ||
|
||
return operation; | ||
} | ||
|
||
return operation; | ||
}, | ||
}); | ||
|
||
writeFileSync( | ||
resolve('public', 'open-api.json'), | ||
JSON.stringify(document, null, 2), | ||
'utf8', | ||
); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err); | ||
|
||
process.exitCode = process.exitCode ?? 1; | ||
process.exit(); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@intake24/common/*": ["../../packages/common/src/*"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.