docs: adjust parameters for v2 methods other than POST

This commit is contained in:
Johann150 2023-01-26 13:25:13 +01:00
parent 05f8172ce9
commit 36031c083a
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
13 changed files with 51 additions and 6 deletions

View file

@ -693,6 +693,14 @@ export interface IEndpointMeta {
* @example (v0) /api/notes/create -> /api/v2/notes
*/
readonly alias?: string;
/**
* If any path parameters were used, they have to be listed here.
* Otherwise they will show up as query parameters in the documentation.
*
* Note: Path parameters cannot be optional.
*/
readonly pathParamers?: string[];
};
}

View file

@ -25,6 +25,7 @@ export const meta = {
v2: {
method: 'get',
alias: 'notes/:noteId/children',
pathParameters: ['noteId'],
},
} as const;

View file

@ -22,6 +22,7 @@ export const meta = {
v2: {
method: 'get',
alias: 'notes/:noteId/clips',
pathParameters: ['noteId'],
},
errors: ['NO_SUCH_NOTE'],

View file

@ -22,6 +22,7 @@ export const meta = {
v2: {
method: 'get',
alias: 'notes/:noteId/conversation',
pathParameters: ['noteId'],
},
errors: ['NO_SUCH_NOTE'],

View file

@ -22,6 +22,7 @@ export const meta = {
v2: {
method: 'delete',
alias: 'notes/:noteId',
pathParameters: ['noteId'],
},
errors: ['ACCESS_DENIED', 'NO_SUCH_NOTE'],

View file

@ -25,7 +25,8 @@ export const meta = {
v2: {
method: 'get',
alias: 'notes/:noteId/reactions/:type?',
alias: 'notes/:noteId/reactions',
pathParameters: ['noteId'],
},
errors: ['NO_SUCH_NOTE'],

View file

@ -25,6 +25,7 @@ export const meta = {
v2: {
method: 'get',
alias: 'notes/:noteId/renotes',
pathParameters: ['noteId'],
},
errors: ['NO_SUCH_NOTE'],

View file

@ -25,6 +25,7 @@ export const meta = {
v2: {
method: 'get',
alias: 'notes/:noteId/replies',
pathParameters: ['noteId'],
},
errors: ['NO_SUCH_NOTE'],

View file

@ -17,6 +17,7 @@ export const meta = {
v2: {
method: 'get',
alias: 'notes/:noteId',
pathParameters: ['noteId'],
},
errors: ['NO_SUCH_NOTE'],

View file

@ -30,6 +30,7 @@ export const meta = {
v2: {
method: 'get',
alias: 'notes/:noteId/status',
pathParameters: ['noteId'],
},
errors: ['NO_SUCH_NOTE'],

View file

@ -57,7 +57,8 @@ export const meta = {
v2: {
method: 'get',
alias: 'notes/:noteId/translate/:targetLang/:sourceLang?',
alias: 'notes/:noteId/translate/:targetLang',
pathParameters: ['noteId', 'targetLang'],
},
errors: ['NO_SUCH_NOTE'],

View file

@ -22,6 +22,7 @@ export const meta = {
v2: {
method: 'delete',
alias: 'notes/:noteId/renotes',
pathParameters: ['noteId'],
},
errors: ['NO_SUCH_NOTE'],

View file

@ -126,10 +126,10 @@ export function genOpenapiSpec() {
};
}
let desc = endpoint.meta.description ?? 'No description provided.');
let desc = endpoint.meta.description ?? 'No description provided.';
desc += `**Credential required**: *${endpoint.meta.requireCredential ? 'Yes' : 'No'}*`;
if (endpoint.meta.kind) {
desc += `\n\n**Permission**: `' + endpoint.meta.kind + '`';
desc += '\n\n**Permission**: `' + endpoint.meta.kind + '`';
}
if (endpoint.meta.limit) {
const limit = endpoint.meta.limit;
@ -220,11 +220,37 @@ export function genOpenapiSpec() {
spec.paths['/' + endpoint.name] = path;
if (endpoint.meta.v2) {
const route = `/v2/${endpoint.meta.v2.alias ?? endpoint.name.replace(/-/g, '_')}`;
// we need a clone of the API endpoint info because otherwise we change it by reference
const infoClone = structuredClone(info);
const route = `/v2/${endpoint.meta.v2.alias ?? endpoint.name.replace(/-/g, '_')}`;
// fix the way parameters are passed
const hasBody = !(endpoint.meta.v2.method === 'get' || endpoint.meta.v2.method === 'delete');
if (!hasBody) {
// these methods do not (usually) have a body
delete infoClone.requestBody;
infoClone.parameters = [];
for (const name in schema.properties) {
infoClone.parameters.push({
name,
in: endpoint.meta.v2?.pathParameters?.includes(name) ? 'path' : 'query',
schema: schema.properties[name],
required: endpoint.meta.v2?.pathParameters?.includes(name) || schema.required?.includes(name) || false,
});
}
} else if (endpoint.meta.v2.pathParameters) {
for (const name in endpoint.meta.v2.pathParameters) {
delete infoClone.requestBody.content[requestType].schema.properties[name];
infoClone.parameters.push({
name,
in: 'path',
schema: schema.properties[name],
required: true,
});
}
}
infoClone['operationId'] = infoClone['summary'] = route;
infoClone['operationId'] = endpoint.meta.v2.method.toUpperCase() + '/' + route;
infoClone['summary'] = endpoint.meta.v2.method.toUpperCase() + ' ' + route;
spec.paths[route] = {
...spec.paths[route],