docs: adjust parameters for v2 methods other than POST
All checks were successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/lint-client Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
All checks were successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/lint-client Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
This commit is contained in:
parent
05f8172ce9
commit
36031c083a
13 changed files with 51 additions and 6 deletions
|
@ -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[];
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ export const meta = {
|
|||
v2: {
|
||||
method: 'get',
|
||||
alias: 'notes/:noteId/children',
|
||||
pathParameters: ['noteId'],
|
||||
},
|
||||
} as const;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ export const meta = {
|
|||
v2: {
|
||||
method: 'get',
|
||||
alias: 'notes/:noteId/clips',
|
||||
pathParameters: ['noteId'],
|
||||
},
|
||||
|
||||
errors: ['NO_SUCH_NOTE'],
|
||||
|
|
|
@ -22,6 +22,7 @@ export const meta = {
|
|||
v2: {
|
||||
method: 'get',
|
||||
alias: 'notes/:noteId/conversation',
|
||||
pathParameters: ['noteId'],
|
||||
},
|
||||
|
||||
errors: ['NO_SUCH_NOTE'],
|
||||
|
|
|
@ -22,6 +22,7 @@ export const meta = {
|
|||
v2: {
|
||||
method: 'delete',
|
||||
alias: 'notes/:noteId',
|
||||
pathParameters: ['noteId'],
|
||||
},
|
||||
|
||||
errors: ['ACCESS_DENIED', 'NO_SUCH_NOTE'],
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -25,6 +25,7 @@ export const meta = {
|
|||
v2: {
|
||||
method: 'get',
|
||||
alias: 'notes/:noteId/renotes',
|
||||
pathParameters: ['noteId'],
|
||||
},
|
||||
|
||||
errors: ['NO_SUCH_NOTE'],
|
||||
|
|
|
@ -25,6 +25,7 @@ export const meta = {
|
|||
v2: {
|
||||
method: 'get',
|
||||
alias: 'notes/:noteId/replies',
|
||||
pathParameters: ['noteId'],
|
||||
},
|
||||
|
||||
errors: ['NO_SUCH_NOTE'],
|
||||
|
|
|
@ -17,6 +17,7 @@ export const meta = {
|
|||
v2: {
|
||||
method: 'get',
|
||||
alias: 'notes/:noteId',
|
||||
pathParameters: ['noteId'],
|
||||
},
|
||||
|
||||
errors: ['NO_SUCH_NOTE'],
|
||||
|
|
|
@ -30,6 +30,7 @@ export const meta = {
|
|||
v2: {
|
||||
method: 'get',
|
||||
alias: 'notes/:noteId/status',
|
||||
pathParameters: ['noteId'],
|
||||
},
|
||||
|
||||
errors: ['NO_SUCH_NOTE'],
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -22,6 +22,7 @@ export const meta = {
|
|||
v2: {
|
||||
method: 'delete',
|
||||
alias: 'notes/:noteId/renotes',
|
||||
pathParameters: ['noteId'],
|
||||
},
|
||||
|
||||
errors: ['NO_SUCH_NOTE'],
|
||||
|
|
|
@ -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],
|
||||
|
|
Loading…
Reference in a new issue