Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ tests/
docs/
node_modules/
src/
dist/*.map
dist/*.map
package-lock.json
30 changes: 20 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"node-fetch": "^3.3.2",
"yargs": "^17.7.2",
"yargs": "^17.7.2"
},
"devDependencies": {
"@types/yargs": "^17.0.33",
Expand Down
56 changes: 30 additions & 26 deletions src/generateEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,36 +56,40 @@ function getSchemaType(
}

function getResponseType(responses: OpenAPIV3.ResponsesObject): string {
const successResponses = ["200", "201", "204"];
for (const status of successResponses) {
const response = responses[status];
if (response && "content" in response) {
const content = response.content;
if (content) {
if (
"application/pdf" in content ||
"application/octet-stream" in content
) {
const schema =
content["application/pdf"]?.schema ||
content["application/octet-stream"]?.schema;
if (schema) {
return getSchemaType(schema, "application/pdf");
}
}
if ("application/json" in content) {
const schema = content["application/json"].schema;
if (schema) {
return getSchemaType(schema, "application/json");
}
const successResponses = new Set(["200", "201", "204"]);

for (const [status, response] of Object.entries(responses)) {
if (!successResponses.has(status) || !response){
continue;
}

if (typeof response !== 'object' || response === null) {
continue;
}

if (!('content' in response) || !response.content) {
return 'void';
}

const content = response.content;
const supportedTypes = [
'application/pdf',
'application/octet-stream',
'application/json'
] as const;

for (const type of supportedTypes) {
const schemaContent = content[type];
if (schemaContent && 'schema' in schemaContent) {
const schema = schemaContent.schema;
if (schema) {
return getSchemaType(schema, type);
}
}
} else if (response) {
// For responses without content (e.g., 204 No Content)
return "void";
}
}
return "any";

return 'any';
}

function getRequestBodyType(
Expand Down