Skip to content
Open
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
70 changes: 51 additions & 19 deletions projects/openapi/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,60 @@ import { traktContract } from '@trakt/api';
import { generateOpenApi } from './generateOpenApi.ts';

export function generate(): ReturnType<typeof generateOpenApi> {
return generateOpenApi(traktContract, {
info: {
title: 'Trakt API',
version: '2.0.0',
return generateOpenApi(
traktContract,
{
info: {
title: 'Trakt API',
version: '2.0.0',
},
components: {
securitySchemes: {
traktOAuth: {
type: 'oauth2',
flows: {
authorizationCode: {
authorizationUrl: 'https://api.trakt.tv/oauth/authorize',
tokenUrl: 'https://api.trakt.tv/oauth/token',
scopes: {
public: 'Access public data',
},
},
},
},
},
},
},
}, {
operationMapper: (operation, route, id) => {
const parts = [
...(operation.tags ?? []),
id,
];
{
operationMapper: (operation, route, id) => {
const parts = [
...(operation.tags ?? []),
id,
];

return {
...operation,
operationId: `${route.method.toLowerCase()}${
parts
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
.join('')
}`,
};
const isOAuthRoute = (operation.tags ?? []).includes('oauth');

const security = isOAuthRoute
? []
: [
{
traktOAuth: [],
},
{},
];

return {
...operation,
security,
operationId: `${route.method.toLowerCase()}${
parts
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
.join('')
}`,
};
},
},
});
);
}

if (import.meta.main) {
Expand Down
Loading