Skip to content

Commit 9b42bbc

Browse files
Copilotabraham
andcommitted
Implement createApp scopes override with format and no enum
Co-authored-by: abraham <[email protected]>
1 parent ad70f38 commit 9b42bbc

File tree

4 files changed

+59
-61
lines changed

4 files changed

+59
-61
lines changed

dist/schema.json

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5124,55 +5124,8 @@
51245124
},
51255125
"scopes": {
51265126
"type": "string",
5127-
"description": "Space separated list of scopes. If none is provided, defaults to `read`. See [OAuth Scopes] for a list of possible scopes.",
5128-
"enum": [
5129-
"profile",
5130-
"read",
5131-
"write",
5132-
"push",
5133-
"follow",
5134-
"admin:read",
5135-
"admin:write",
5136-
"read:accounts",
5137-
"read:blocks",
5138-
"read:bookmarks",
5139-
"read:favourites",
5140-
"read:filters",
5141-
"read:follows",
5142-
"read:lists",
5143-
"read:mutes",
5144-
"read:notifications",
5145-
"read:search",
5146-
"read:statuses",
5147-
"write:accounts",
5148-
"write:blocks",
5149-
"write:bookmarks",
5150-
"write:conversations",
5151-
"write:favourites",
5152-
"write:filters",
5153-
"write:follows",
5154-
"write:lists",
5155-
"write:media",
5156-
"write:mutes",
5157-
"write:notifications",
5158-
"write:reports",
5159-
"write:statuses",
5160-
"admin:read:accounts",
5161-
"admin:read:reports",
5162-
"admin:read:domain_allows",
5163-
"admin:read:domain_blocks",
5164-
"admin:read:ip_blocks",
5165-
"admin:read:email_domain_blocks",
5166-
"admin:read:canonical_email_blocks",
5167-
"admin:write:accounts",
5168-
"admin:write:reports",
5169-
"admin:write:domain_allows",
5170-
"admin:write:domain_blocks",
5171-
"admin:write:ip_blocks",
5172-
"admin:write:email_domain_blocks",
5173-
"admin:write:canonical_email_blocks"
5174-
],
5175-
"default": "read"
5127+
"format": "scopes",
5128+
"description": "Space separated list of scopes. If none is provided, defaults to `read`. See [OAuth Scopes] for a list of possible scopes."
51765129
},
51775130
"website": {
51785131
"type": "string",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { MethodParser } from '../../parsers/MethodParser';
2+
import { EntityParser } from '../../parsers/EntityParser';
3+
import { OpenAPIGenerator } from '../../generators/OpenAPIGenerator';
4+
5+
describe('CreateApp scopes override', () => {
6+
test('should override scopes property to use format scopes without enum for createApp operation', () => {
7+
const methodParser = new MethodParser();
8+
const entityParser = new EntityParser();
9+
10+
const entities = entityParser.parseAllEntities();
11+
const methodFiles = methodParser.parseAllMethods();
12+
13+
const generator = new OpenAPIGenerator();
14+
const spec = generator.generateSchema(entities, methodFiles);
15+
16+
// Find the createApp operation (POST /api/v1/apps)
17+
const appsPath = spec.paths['/api/v1/apps'];
18+
expect(appsPath).toBeDefined();
19+
expect(appsPath.post).toBeDefined();
20+
21+
// Check the request body schema
22+
const requestBody = appsPath.post!.requestBody as any;
23+
expect(requestBody).toBeDefined();
24+
expect(requestBody.content).toBeDefined();
25+
expect(requestBody.content['application/json']).toBeDefined();
26+
27+
const schema = requestBody.content['application/json'].schema as any;
28+
expect(schema).toBeDefined();
29+
expect(schema.properties).toBeDefined();
30+
31+
// Verify scopes property has the correct format
32+
const scopesProperty = schema.properties.scopes;
33+
expect(scopesProperty).toBeDefined();
34+
expect(scopesProperty.type).toBe('string');
35+
expect(scopesProperty.format).toBe('scopes');
36+
37+
// Ensure it does NOT have enum values
38+
expect(scopesProperty.enum).toBeUndefined();
39+
40+
// Verify the description is preserved
41+
expect(scopesProperty.description).toContain('scopes');
42+
});
43+
});

src/__tests__/integration/oauth-scopes-consolidation.test.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { EntityParser } from '../../parsers/EntityParser';
33
import { MethodParser } from '../../parsers/MethodParser';
44

55
describe('OAuth Scopes Consolidation', () => {
6-
test('should consolidate OAuth scopes across Application, CredentialApplication, and createApp', () => {
6+
test('should consolidate OAuth scopes for Application and CredentialApplication, and override createApp scopes', () => {
77
// Parse entities and methods
88
const entityParser = new EntityParser();
99
const entities = entityParser.parseAllEntities();
@@ -47,23 +47,16 @@ describe('OAuth Scopes Consolidation', () => {
4747
'#/components/schemas/OAuthScopes'
4848
);
4949

50-
// Check that createApp requestBody has OAuth scope enum (should be unchanged)
50+
// Check that createApp requestBody uses format scopes (changed behavior)
5151
const createAppOperation = spec.paths['/api/v1/apps']?.post;
5252
expect(createAppOperation).toBeDefined();
5353

5454
const requestBodySchema = createAppOperation!.requestBody?.content?.[
5555
'application/json'
5656
]?.schema as any;
57-
expect(requestBodySchema?.properties?.scopes?.enum).toBeDefined();
58-
expect(requestBodySchema.properties.scopes.enum).toContain('read');
59-
expect(requestBodySchema.properties.scopes.enum).toContain('write');
60-
expect(requestBodySchema.properties.scopes.enum).toContain('profile');
61-
expect(requestBodySchema.properties.scopes.enum.length).toBeGreaterThan(40);
62-
63-
// Verify that all three places have the same number of scopes
64-
const oauthScopeCount = oauthScope.enum.length;
65-
const createAppScopeCount = requestBodySchema.properties.scopes.enum.length;
66-
expect(oauthScopeCount).toBe(createAppScopeCount);
57+
expect(requestBodySchema?.properties?.scopes?.type).toBe('string');
58+
expect(requestBodySchema?.properties?.scopes?.format).toBe('scopes');
59+
expect(requestBodySchema?.properties?.scopes?.enum).toBeUndefined();
6760
});
6861

6962
test('should maintain backwards compatibility for scope descriptions', () => {

src/generators/MethodConverter.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@ class MethodConverter {
298298
description: properties.redirect_uris.description,
299299
};
300300

301+
// Override scopes to use format scopes without enum values
302+
if (properties.scopes) {
303+
properties.scopes = {
304+
type: 'string',
305+
format: 'scopes',
306+
description: properties.scopes.description,
307+
};
308+
}
309+
301310
// Default behavior for createApp endpoint
302311
operation.requestBody = {
303312
description: 'JSON request body parameters',

0 commit comments

Comments
 (0)