Skip to content
Merged
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
8 changes: 6 additions & 2 deletions src/cli/swagger-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
);

try {
let spec: any;

Check warning on line 22 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (22.x)

Unexpected any. Specify a different type

Check warning on line 22 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 22 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (20.x)

Unexpected any. Specify a different type

Check warning on line 22 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 22 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 22 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 22 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, windows-latest)

Unexpected any. Specify a different type

Check warning on line 22 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, windows-latest)

Unexpected any. Specify a different type
const response = await fetch(url);

if (!response.ok) {
Expand Down Expand Up @@ -86,12 +86,16 @@
return;
}

let typeDefinitions = `/**\n * Auto-generated types from Swagger/OpenAPI\n * Generated at ${new Date().toISOString()}\n */\n\n`;
const typeDefinitionsArray = [
`/**\n * Auto-generated types from Swagger/OpenAPI\n * Generated at ${new Date().toISOString()}\n */`,
];

for (const [name, schema] of Object.entries(schemas)) {
typeDefinitions += generateInterface(name, schema as any) + "\n\n";
typeDefinitionsArray.push(generateInterface(name, schema as any));

Check warning on line 94 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (22.x)

Unexpected any. Specify a different type

Check warning on line 94 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 94 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (20.x)

Unexpected any. Specify a different type

Check warning on line 94 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 94 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 94 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 94 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, windows-latest)

Unexpected any. Specify a different type

Check warning on line 94 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, windows-latest)

Unexpected any. Specify a different type
}

const typeDefinitions = typeDefinitionsArray.join("\n\n") + "\n\n";

const outputPath = path.join(process.cwd(), output);
const outputDir = path.dirname(outputPath);

Expand All @@ -109,7 +113,7 @@
}
}

function generateInterface(name: string, schema: any): string {

Check warning on line 116 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (22.x)

Unexpected any. Specify a different type

Check warning on line 116 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 116 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (20.x)

Unexpected any. Specify a different type

Check warning on line 116 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 116 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 116 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 116 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, windows-latest)

Unexpected any. Specify a different type

Check warning on line 116 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, windows-latest)

Unexpected any. Specify a different type
// Sanitize name (remove invalid characters)
const sanitizedName = name.replace(/[^a-zA-Z0-9]/g, "");

Expand All @@ -126,7 +130,7 @@
const required = schema.required || [];

const props = Object.entries(properties)
.map(([propName, propSchema]: [string, any]) => {

Check warning on line 133 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (22.x)

Unexpected any. Specify a different type

Check warning on line 133 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 133 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (20.x)

Unexpected any. Specify a different type

Check warning on line 133 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 133 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 133 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 133 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, windows-latest)

Unexpected any. Specify a different type

Check warning on line 133 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, windows-latest)

Unexpected any. Specify a different type
const isRequired = required.includes(propName);
const type = mapOpenApiToTs(propSchema);
return ` ${propName}${isRequired ? "" : "?"}: ${type};`;
Expand All @@ -141,7 +145,7 @@
}
if (schema.enum) {
const values = schema.enum
.map((v: any) => (typeof v === "string" ? `'${v}'` : v))

Check warning on line 148 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (22.x)

Unexpected any. Specify a different type

Check warning on line 148 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 148 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (20.x)

Unexpected any. Specify a different type

Check warning on line 148 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 148 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 148 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 148 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, windows-latest)

Unexpected any. Specify a different type

Check warning on line 148 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, windows-latest)

Unexpected any. Specify a different type
.join(" | ");
return `export type ${sanitizedName} = ${values};`;
}
Expand All @@ -149,7 +153,7 @@
return `export type ${sanitizedName} = ${mapOpenApiToTs(schema)};`;
}

function mapOpenApiToTs(schema: any): string {

Check warning on line 156 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (22.x)

Unexpected any. Specify a different type

Check warning on line 156 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 156 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (20.x)

Unexpected any. Specify a different type

Check warning on line 156 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 156 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 156 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 156 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, windows-latest)

Unexpected any. Specify a different type

Check warning on line 156 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, windows-latest)

Unexpected any. Specify a different type
if (!schema) return "any";

// Handle references
Expand Down Expand Up @@ -181,13 +185,13 @@
default:
// Handle combinations (oneOf, anyOf, allOf)
if (schema.oneOf || schema.anyOf) {
const types = (schema.oneOf || schema.anyOf).map((s: any) =>

Check warning on line 188 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (22.x)

Unexpected any. Specify a different type

Check warning on line 188 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 188 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (20.x)

Unexpected any. Specify a different type

Check warning on line 188 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 188 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 188 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 188 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, windows-latest)

Unexpected any. Specify a different type

Check warning on line 188 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, windows-latest)

Unexpected any. Specify a different type
mapOpenApiToTs(s)
);
return `(${types.join(" | ")})`;
}
if (schema.allOf) {
const types = schema.allOf.map((s: any) => mapOpenApiToTs(s));

Check warning on line 194 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (22.x)

Unexpected any. Specify a different type

Check warning on line 194 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 194 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / Run Tests (20.x)

Unexpected any. Specify a different type

Check warning on line 194 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 194 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 194 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, macos-latest)

Unexpected any. Specify a different type

Check warning on line 194 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (20.x, windows-latest)

Unexpected any. Specify a different type

Check warning on line 194 in src/cli/swagger-generator.ts

View workflow job for this annotation

GitHub Actions / build (22.x, windows-latest)

Unexpected any. Specify a different type
return `(${types.join(" & ")})`;
}
return "any";
Expand Down
Loading