summaryrefslogtreecommitdiff
path: root/packages/misskey-js/generator/src
diff options
context:
space:
mode:
authorかっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>2024-09-06 17:22:45 +0900
committerGitHub <noreply@github.com>2024-09-06 17:22:45 +0900
commit8d19bdbb65c79e2425bf5c73fd8b6310670a8c10 (patch)
treeb80183562a1befd90686f83b7b59ced5e03d6388 /packages/misskey-js/generator/src
parentrefactor(frontend): scss deprecated 警告に対応 (#14513) (diff)
downloadsharkey-8d19bdbb65c79e2425bf5c73fd8b6310670a8c10.tar.gz
sharkey-8d19bdbb65c79e2425bf5c73fd8b6310670a8c10.tar.bz2
sharkey-8d19bdbb65c79e2425bf5c73fd8b6310670a8c10.zip
fix(misskey-js): content-typeはapplication/jsonでないもののみを記録するように (#14508)
Diffstat (limited to 'packages/misskey-js/generator/src')
-rw-r--r--packages/misskey-js/generator/src/generator.ts21
1 files changed, 10 insertions, 11 deletions
diff --git a/packages/misskey-js/generator/src/generator.ts b/packages/misskey-js/generator/src/generator.ts
index 4ae00a4522..88f2ae9ee9 100644
--- a/packages/misskey-js/generator/src/generator.ts
+++ b/packages/misskey-js/generator/src/generator.ts
@@ -96,15 +96,11 @@ async function generateEndpoints(
endpoint.request = req;
const reqType = new EndpointReqMediaType(path, req);
- endpointReqMediaTypesSet.add(reqType.getMediaType());
- endpointReqMediaTypes.push(reqType);
- } else {
- endpointReqMediaTypesSet.add('application/json');
- endpointReqMediaTypes.push(new EndpointReqMediaType(path, undefined, 'application/json'));
+ if (reqType.getMediaType() !== 'application/json') {
+ endpointReqMediaTypesSet.add(reqType.getMediaType());
+ endpointReqMediaTypes.push(reqType);
+ }
}
- } else {
- endpointReqMediaTypesSet.add('application/json');
- endpointReqMediaTypes.push(new EndpointReqMediaType(path, undefined, 'application/json'));
}
if (operation.responses && isResponseObject(operation.responses['200']) && operation.responses['200'].content) {
@@ -158,16 +154,19 @@ async function generateEndpoints(
endpointOutputLine.push('');
function generateEndpointReqMediaTypesType() {
- return `Record<keyof Endpoints, ${[...endpointReqMediaTypesSet].map((t) => `'${t}'`).join(' | ')}>`;
+ return `{ [K in keyof Endpoints]?: ${[...endpointReqMediaTypesSet].map((t) => `'${t}'`).join(' | ')}; }`;
}
- endpointOutputLine.push(`export const endpointReqTypes: ${generateEndpointReqMediaTypesType()} = {`);
+ endpointOutputLine.push(`/**
+ * NOTE: The content-type for all endpoints not listed here is application/json.
+ */`);
+ endpointOutputLine.push('export const endpointReqTypes = {');
endpointOutputLine.push(
...endpointReqMediaTypes.map(it => '\t' + it.toLine()),
);
- endpointOutputLine.push('};');
+ endpointOutputLine.push(`} as const satisfies ${generateEndpointReqMediaTypesType()};`);
endpointOutputLine.push('');
await writeFile(endpointOutputPath, endpointOutputLine.join('\n'));