Skip to content

Commit d13ed76

Browse files
committed
CI fixes
1 parent 0b61f50 commit d13ed76

12 files changed

Lines changed: 34 additions & 25 deletions

File tree

.husky/pre-commit

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env sh
22
set -e
33

4+
unset DATABASE_URL
5+
46
echo "Running Auto-Code-Format Fix..."
57
npm run format || true
68
git add -u
@@ -95,7 +97,7 @@ if [ "$USE_PRISM" -eq 0 ]; then
9597
echo "JVM server is ready."
9698
cat << 'EOF' > test-sdks.ts
9799
import { StoreClient as SwaggerStoreClient } from './.test_out_swagger/dist/services/store.client.js';
98-
import { StoreClient as OpenApiStoreClient } from './.test_out_openapi/dist/services/store.client.js';
100+
import { PetsClient as OpenApiPetsClient } from './.test_out_openapi/dist/services/pets.client.js';
99101
100102
async function run() {
101103
console.log("Testing Swagger 2.0 SDK against JVM Server...");
@@ -104,8 +106,8 @@ async function run() {
104106
console.log("Swagger 2.0 OK");
105107
106108
console.log("Testing OpenAPI 3.0 SDK against JVM Server...");
107-
const openapiClient = new OpenApiStoreClient('http://127.0.0.1:8080/api');
108-
await openapiClient.getInventory({ headers: { api_key: 'special-key' } });
109+
const openapiClient = new OpenApiPetsClient('http://127.0.0.1:8080/v1');
110+
await openapiClient.listPets();
109111
console.log("OpenAPI 3.0 OK");
110112
}
111113
run().catch(e => { console.error(e); process.exit(1); });
@@ -135,7 +137,7 @@ if [ "$USE_PRISM" -eq 1 ]; then
135137

136138
cat << 'EOF' > test-sdks.ts
137139
import { StoreClient as SwaggerStoreClient } from './.test_out_swagger/dist/services/store.client.js';
138-
import { StoreClient as OpenApiStoreClient } from './.test_out_openapi/dist/services/store.client.js';
140+
import { PetsClient as OpenApiPetsClient } from './.test_out_openapi/dist/services/pets.client.js';
139141
140142
async function run() {
141143
console.log("Testing Swagger 2.0 SDK against fallback mock...");
@@ -144,8 +146,8 @@ async function run() {
144146
console.log("Swagger 2.0 OK");
145147
146148
console.log("Testing OpenAPI 3.0 SDK against fallback mock...");
147-
const openapiClient = new OpenApiStoreClient('http://127.0.0.1:4011');
148-
await openapiClient.getInventory({ headers: { api_key: 'special-key' } });
149+
const openapiClient = new OpenApiPetsClient('http://127.0.0.1:4011');
150+
await openapiClient.listPets();
149151
console.log("OpenAPI 3.0 OK");
150152
}
151153
run().catch(e => { console.error(e); process.exit(1); });
@@ -164,7 +166,7 @@ SERVER_OAS3_PID=$!
164166

165167
echo "Waiting for generated servers to start..."
166168
for i in {1..30}; do
167-
if curl -s http://127.0.0.1:4020/user > /dev/null && curl -s http://127.0.0.1:4021/user > /dev/null; then
169+
if curl -s http://127.0.0.1:4020/user > /dev/null && curl -s http://127.0.0.1:4021/pet > /dev/null; then
168170
echo "Servers are up!"
169171
break
170172
fi
@@ -173,7 +175,6 @@ done
173175

174176
cat << 'EOF' > test-generated-servers.ts
175177
import { UserClient as SwaggerUserClient } from './.test_out_swagger/dist/services/user.client.js';
176-
import { UserClient as OpenApiUserClient } from './.test_out_openapi/dist/services/user.client.js';
177178
178179
async function run() {
179180
console.log("Testing Swagger 2.0 SDK against Generated Swagger Server...");
@@ -197,8 +198,8 @@ async function run() {
197198
198199
console.log("Testing OpenAPI 3.0 SDK against Generated OpenAPI Server...");
199200
// Fallback to fetch just to prove the DB and routing are alive if the SDK mismatches
200-
const res = await fetch('http://127.0.0.1:4021/user');
201-
if (!res.ok) throw new Error("Generated OpenAPI server failed to respond to GET /user");
201+
const res = await fetch('http://127.0.0.1:4021/pet');
202+
if (!res.ok) throw new Error("Generated OpenAPI server failed to respond to GET /pet");
202203
const data = await res.json();
203204
if (!Array.isArray(data) || data.length === 0) throw new Error("Generated OpenAPI server did not seed data");
204205
console.log("OpenAPI 3.0 Generated Server OK (Seeded " + data.length + " users)");

ci_local.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#!/usr/bin/env sh
22
set -e
33

4+
rm -rf .test_out_swagger
5+
rm -rf .test_out_openapi
6+
rm -rf .test_out_server_swagger
7+
rm -rf .test_out_server_openapi
8+
9+
unset DATABASE_URL
10+
411
echo "Running Lint..."
512
npm run lint
613

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ export async function generateFromOpenApi(
372372
if (targetScope === "to_server") {
373373
fs.writeFileSync(
374374
path.join(targetOutputRoot, "vitest.config.ts"),
375-
"import { defineConfig } from 'vitest/config';\nexport default defineConfig({ test: { include: ['src/**/*.spec.ts', 'src/**/*.test.ts'] } });\n",
375+
"import { defineConfig } from 'vitest/config';\nexport default defineConfig({ test: { pool: 'forks', include: ['src/**/*.spec.ts', 'src/**/*.test.ts'] } });\n",
376376
);
377377
const readmeContent = `# Generated Mock Server
378378

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ export function generateFromConfigSync(
209209
if (
210210
schema.definition &&
211211
typeof schema.definition === "object" &&
212-
schema.definition.type === "object"
212+
(schema.definition.type === "object" ||
213+
(schema.definition.properties &&
214+
Object.keys(schema.definition.properties).length > 0))
213215
) {
214216
schemaNamesList.push(schema.name);
215217
serverGenerator.generateEntityRoutes(

src/routes/emit_server_url.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class ServerUrlGenerator {
124124
.writeLine("if (!server) {")
125125
.indent(() => {
126126
writer.writeLine(
127-
"throw new Error(`Server not found: ${indexOrDescription}`);",
127+
"throw new globalThis.Error(`Server not found: ${indexOrDescription}`);",
128128
);
129129
})
130130
.writeLine("}");
@@ -149,7 +149,7 @@ export class ServerUrlGenerator {
149149
)
150150
.indent(() => {
151151
writer.writeLine(
152-
'throw new Error(`Value "${value}" for variable "${key}" is not in the allowed enum: ${config.enum.join(\', \')}`);',
152+
'throw new globalThis.Error(`Value "${value}" for variable "${key}" is not in the allowed enum: ${config.enum.join(\', \')}`);',
153153
);
154154
})
155155
.writeLine("}");

src/vendors/angular/test/service-test-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export class ServiceTestGenerator {
273273
);
274274

275275
tests.push(
276-
` next: () => { throw new Error('should have failed with a 404 error'); },`,
276+
` next: () => { throw new globalThis.Error('should have failed with a 404 error'); },`,
277277
);
278278

279279
tests.push(` error: error => expect(error.status).toBe(404),`);

src/vendors/angular/utils/link-service.generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class LinkServiceGenerator {
199199
const value = variable.default || '';
200200
201201
if (variable.enum && Array.isArray(variable.enum) && !variable.enum.includes(value)) {
202-
throw new Error(\`Value "\${value}" for variable "\${key}" is not in the allowed enum: \${variable.enum.join(', ')}\`);
202+
throw new globalThis.Error(\`Value "\${value}" for variable "\${key}" is not in the allowed enum: \${variable.enum.join(', ')}\`);
203203
}
204204
205205
url = url.replace(new RegExp('{' + key + '}', 'g'), value);

src/vendors/express/express-server.generator.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,10 @@ export function createMcpRouter() {
312312
.map((schema) => {
313313
return `
314314
if (dataSource) {
315-
app.use('/${schema.toLowerCase()}', create${schema}Router(dataSource));
315+
app.use('/${schema.toLowerCase()}', create${schema}Router(dataSource));
316316
} else {
317-
// Fallback to stub routes or no-op if no DB (the default routes without DB)
318-
// Note: For full stub mode, your router generator should output stub DAOs.
319-
app.use('/${schema.toLowerCase()}', create${schema}Router(null as any));
317+
// Fallback to stub routes or no-op if no DB
318+
app.use('/${schema.toLowerCase()}', express.Router().use((req, res) => res.status(501).json({ error: "Not Implemented (No DB)" })));
320319
}`;
321320
})
322321
.join("\n")}

src/vendors/fetch/service/service-method.generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class FetchServiceMethodGenerator {
185185
lines.push(`const response = await fetch(url.toString(), fetchOptions);`);
186186

187187
lines.push(
188-
`if (!response.ok) { throw new Error('Request failed: ' + response.statusText); }`,
188+
`if (!response.ok) { throw new globalThis.Error('Request failed: ' + response.statusText); }`,
189189
);
190190

191191
// Basic parsing for now

src/vendors/typeorm/dao.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function generateStub(project: Project, schemaName: string, daoDir: string) {
9090
parameters: [{ name: "data", type: `Partial<${schemaName}>` }],
9191
returnType: `Promise<${schemaName}>`,
9292
docs: [{ description: `Creates a new ${schemaName} record.` }],
93-
statements: `throw new Error("NotImplementedError");`,
93+
statements: `throw new globalThis.Error("NotImplementedError");`,
9494
});
9595

9696
sourceFile.formatText();

0 commit comments

Comments
 (0)