Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/publish-contract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
fi
mkdir -p ${{ steps.branch.outputs.BRANCH }}
cp ../openapi.json ${{ steps.branch.outputs.BRANCH }}/openapi.json
cp ../openapi.yaml ${{ steps.branch.outputs.BRANCH }}/openapi.yaml
git config user.name "contract-bot"
git config user.email "bot@faculytics.com"
git add .
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ lerna-debug.log*
# dotenv environment variable files
.env
openapi.json
openapi.yaml
.env.development.local
.env.test.local
.env.production.local
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"dataloader": "^2.2.3",
"dotenv": "^17.2.4",
"exceljs": "^4.4.0",
"js-yaml": "^4.1.1",
"nestjs-pino": "^4.6.0",
"p-limit": "^7.3.0",
"passport-jwt": "^4.0.1",
Expand All @@ -74,6 +75,7 @@
"@types/bcrypt": "^6.0.0",
"@types/express": "^5.0.0",
"@types/jest": "^30.0.0",
"@types/js-yaml": "^4.0.9",
"@types/node": "^22.10.7",
"@types/passport-jwt": "^4.0.1",
"@types/supertest": "^6.0.2",
Expand Down
16 changes: 14 additions & 2 deletions scripts/generate-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { NestExpressApplication } from '@nestjs/platform-express';
import { swaggerConfig } from '../src/configurations/app/open-api';
import { NestFactory } from '@nestjs/core';
import yaml from 'js-yaml';

async function generate() {
console.log('Generating OpenAPI contract...');
Expand Down Expand Up @@ -37,9 +38,20 @@ async function generate() {
await app.init();

const document = SwaggerModule.createDocument(app, swaggerConfig);
writeFileSync('openapi.json', JSON.stringify(document, null, 2));

console.log('OpenAPI contract generated successfully: openapi.json');
// Remove functions by JSON round-trip
const cleanDocument: unknown = JSON.parse(JSON.stringify(document));

const yamlDocument = yaml.dump(cleanDocument, {
noRefs: true,
lineWidth: 120,
});

writeFileSync('openapi.json', JSON.stringify(cleanDocument, null, 2));
writeFileSync('openapi.yaml', yamlDocument, 'utf8');
console.log(
'OpenAPI contract generated successfully: openapi.json and openapi.yaml',
);

await app.close();
process.exit(0);
Expand Down