Skip to content

Commit f3a9c5d

Browse files
Copilotabraham
andcommitted
Add prettier configuration and format all code
Co-authored-by: abraham <[email protected]>
1 parent 9a4ceab commit f3a9c5d

24 files changed

+281
-182
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
version: 2
77
updates:
8-
- package-ecosystem: "npm"
9-
directory: "/"
8+
- package-ecosystem: 'npm'
9+
directory: '/'
1010
schedule:
11-
interval: "weekly"
11+
interval: 'weekly'

.github/workflows/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ jobs:
2121
- name: Install dependencies
2222
run: npm ci
2323

24+
- name: Check code formatting
25+
run: npm run format:check
26+
2427
- name: Build project
2528
run: npm run build
2629

2730
- name: Run tests
28-
run: npm test
31+
run: npm test

.prettierignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output
5+
dist/
6+
7+
# Coverage reports
8+
coverage/
9+
10+
# Logs
11+
*.log
12+
13+
# Documentation clone
14+
mastodon-documentation/
15+
16+
# Lock files
17+
package-lock.json

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "es5",
4+
"singleQuote": true,
5+
"printWidth": 80,
6+
"tabWidth": 2,
7+
"useTabs": false
8+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# mastodon-openapi
1+
# mastodon-openapi

jest.config.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@ module.exports = {
33
testEnvironment: 'node',
44
roots: ['<rootDir>/src'],
55
testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
6-
collectCoverageFrom: [
7-
'src/**/*.ts',
8-
'!src/**/*.d.ts',
9-
],
10-
};
6+
collectCoverageFrom: ['src/**/*.ts', '!src/**/*.d.ts'],
7+
};

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"test": "jest",
1313
"test:watch": "jest --watch",
1414
"clean": "rm -rf dist",
15+
"format": "prettier --write .",
16+
"format:check": "prettier --check .",
1517
"postinstall": "git clone https://github.com/mastodon/documentation mastodon-documentation || true"
1618
},
1719
"keywords": [
@@ -26,6 +28,7 @@
2628
"@types/js-yaml": "^4.0.9",
2729
"@types/node": "^20.0.0",
2830
"jest": "^29.5.0",
31+
"prettier": "^3.5.3",
2932
"ts-jest": "^29.1.0",
3033
"ts-node": "^10.9.0",
3134
"typescript": "^5.0.0"

src/__tests__/generators/OpenAPIGenerator.test.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ describe('OpenAPIGenerator', () => {
1919
{
2020
name: 'id',
2121
type: 'Integer',
22-
description: 'The ID of the entity'
22+
description: 'The ID of the entity',
2323
},
2424
{
2525
name: 'name',
2626
type: 'String',
2727
description: 'The name of the entity',
28-
optional: true
28+
optional: true,
2929
},
3030
{
3131
name: 'active',
3232
type: 'Boolean',
3333
description: 'Whether the entity is active',
34-
deprecated: true
35-
}
36-
]
37-
}
34+
deprecated: true,
35+
},
36+
],
37+
},
3838
];
3939

4040
const methodFiles: ApiMethodsFile[] = [
@@ -48,7 +48,7 @@ describe('OpenAPIGenerator', () => {
4848
endpoint: '/api/v1/test/:id',
4949
description: 'Retrieve a test entity',
5050
returns: 'TestEntity',
51-
oauth: 'User token + read'
51+
oauth: 'User token + read',
5252
},
5353
{
5454
name: 'Create test entity',
@@ -59,17 +59,17 @@ describe('OpenAPIGenerator', () => {
5959
{
6060
name: 'name',
6161
description: 'Name of the entity',
62-
required: true
62+
required: true,
6363
},
6464
{
6565
name: 'active',
66-
description: 'Whether entity is active'
67-
}
66+
description: 'Whether entity is active',
67+
},
6868
],
69-
oauth: 'User token + write'
70-
}
71-
]
72-
}
69+
oauth: 'User token + write',
70+
},
71+
],
72+
},
7373
];
7474

7575
const spec = generator.generateSchema(entities, methodFiles);
@@ -118,12 +118,14 @@ describe('OpenAPIGenerator', () => {
118118
const postOp = spec.paths['/api/v1/test'].post!;
119119
expect(postOp.summary).toBe('Create test entity');
120120
expect(postOp.requestBody).toBeDefined();
121-
expect(postOp.requestBody?.content['application/x-www-form-urlencoded']).toBeDefined();
121+
expect(
122+
postOp.requestBody?.content['application/x-www-form-urlencoded']
123+
).toBeDefined();
122124
});
123125

124126
it('should handle empty inputs', () => {
125127
const spec = generator.generateSchema([], []);
126-
128+
127129
expect(spec.openapi).toBe('3.0.3');
128130
expect(spec.paths).toEqual({});
129131
expect(spec.components?.schemas).toEqual({});
@@ -134,13 +136,13 @@ describe('OpenAPIGenerator', () => {
134136
it('should return valid JSON string', () => {
135137
const entities: EntityClass[] = [];
136138
const methodFiles: ApiMethodsFile[] = [];
137-
139+
138140
generator.generateSchema(entities, methodFiles);
139141
const json = generator.toJSON();
140-
142+
141143
expect(() => JSON.parse(json)).not.toThrow();
142144
const parsed = JSON.parse(json);
143145
expect(parsed.openapi).toBe('3.0.3');
144146
});
145147
});
146-
});
148+
});

src/__tests__/parsers/EntityParser.test.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,64 +19,72 @@ describe('EntityParser', () => {
1919

2020
test('should parse entities and extract basic structure', () => {
2121
const entities = parser.parseAllEntities();
22-
22+
2323
// Verify we found entities
2424
expect(entities.length).toBeGreaterThan(50); // Should be around 64 entities
25-
25+
2626
// Find a specific entity to test
27-
const accountEntity = entities.find(e => e.name === 'Account');
27+
const accountEntity = entities.find((e) => e.name === 'Account');
2828
expect(accountEntity).toBeDefined();
29-
29+
3030
if (accountEntity) {
3131
expect(accountEntity.name).toBe('Account');
3232
expect(accountEntity.description).toContain('user of Mastodon');
3333
expect(accountEntity.attributes.length).toBeGreaterThan(20); // Account has many attributes
34-
34+
3535
// Check some specific attributes exist
36-
const idAttribute = accountEntity.attributes.find(attr => attr.name === 'id');
36+
const idAttribute = accountEntity.attributes.find(
37+
(attr) => attr.name === 'id'
38+
);
3739
expect(idAttribute).toBeDefined();
3840
expect(idAttribute?.type).toContain('String');
39-
40-
const usernameAttribute = accountEntity.attributes.find(attr => attr.name === 'username');
41+
42+
const usernameAttribute = accountEntity.attributes.find(
43+
(attr) => attr.name === 'username'
44+
);
4145
expect(usernameAttribute).toBeDefined();
4246
expect(usernameAttribute?.type).toBe('String');
4347
}
4448
});
4549

4650
test('should correctly identify optional and deprecated attributes', () => {
4751
const entities = parser.parseAllEntities();
48-
52+
4953
// Find entities with optional/deprecated attributes
5054
let foundOptional = false;
5155
let foundDeprecated = false;
52-
56+
5357
for (const entity of entities) {
5458
for (const attr of entity.attributes) {
5559
if (attr.optional) foundOptional = true;
5660
if (attr.deprecated) foundDeprecated = true;
5761
}
5862
}
59-
63+
6064
expect(foundOptional).toBe(true);
6165
expect(foundDeprecated).toBe(true);
6266
});
6367

6468
test('should parse entity with simple structure', () => {
6569
const entities = parser.parseAllEntities();
66-
70+
6771
// Find Application entity which has a simpler structure
68-
const applicationEntity = entities.find(e => e.name === 'Application');
72+
const applicationEntity = entities.find((e) => e.name === 'Application');
6973
expect(applicationEntity).toBeDefined();
70-
74+
7175
if (applicationEntity) {
7276
expect(applicationEntity.name).toBe('Application');
73-
expect(applicationEntity.description).toContain('interfaces with the REST API');
77+
expect(applicationEntity.description).toContain(
78+
'interfaces with the REST API'
79+
);
7480
expect(applicationEntity.attributes.length).toBeGreaterThan(0);
75-
81+
7682
// Check that name attribute exists
77-
const nameAttribute = applicationEntity.attributes.find(attr => attr.name === 'name');
83+
const nameAttribute = applicationEntity.attributes.find(
84+
(attr) => attr.name === 'name'
85+
);
7886
expect(nameAttribute).toBeDefined();
7987
expect(nameAttribute?.type).toBe('String');
8088
}
8189
});
82-
});
90+
});

0 commit comments

Comments
 (0)