Skip to content

Commit 42aaec7

Browse files
committed
fix: dependency graph
1 parent 09664e8 commit 42aaec7

5 files changed

Lines changed: 30 additions & 24 deletions

File tree

packages/openapi-code-generator/src/core/dependency-graph.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ describe.each(testVersions)("%s - core/dependency-graph", (version) => {
4141
graph.order.indexOf("s_AOrdering"),
4242
)
4343

44+
// check record values schemas are handled correctly.
45+
expect(graph.order.indexOf("s_NamedNullableStringEnum")).toBeLessThan(
46+
graph.order.indexOf("s_AdditionalPropertiesSchema"),
47+
)
48+
4449
expect(graph.order.indexOf("s_Recursive")).toBe(-1)
4550

4651
expect(graph.circular).toStrictEqual(new Set(["s_Recursive"]))

packages/openapi-code-generator/src/core/dependency-graph.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ const getAllSourcesFromSchema = (it: IRModel) => {
3232
allSources.push(...it.anyOf)
3333
}
3434

35-
if (
36-
it.additionalProperties &&
37-
typeof it.additionalProperties !== "boolean"
38-
) {
39-
allSources.push(it.additionalProperties)
35+
if (it.additionalProperties) {
36+
allSources.push(it.additionalProperties.key)
37+
allSources.push(it.additionalProperties.value)
4038
}
4139
} else if (it.type === "array") {
4240
allSources.push(it.items)
41+
} else if (it.type === "record") {
42+
allSources.push(it.key)
43+
allSources.push(it.value)
4344
}
4445

4546
return allSources

packages/openapi-code-generator/src/typescript/common/schema-builders/joi-schema-builder.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,18 +370,18 @@ describe.each(
370370
expect(schemas).toMatchInlineSnapshot(`
371371
"import joi from "joi"
372372
373-
export const s_AdditionalPropertiesSchema = joi
374-
.object()
375-
.pattern(joi.any(), s_NamedNullableStringEnum.required())
376-
.required()
377-
.id("s_AdditionalPropertiesSchema")
378-
379373
export const s_NamedNullableStringEnum = joi
380374
.string()
381375
.valid("", "one", "two", "three")
382376
.allow(null)
383377
.required()
384-
.id("s_NamedNullableStringEnum")"
378+
.id("s_NamedNullableStringEnum")
379+
380+
export const s_AdditionalPropertiesSchema = joi
381+
.object()
382+
.pattern(joi.any(), s_NamedNullableStringEnum.required())
383+
.required()
384+
.id("s_AdditionalPropertiesSchema")"
385385
`)
386386
})
387387

packages/openapi-code-generator/src/typescript/common/schema-builders/zod-v3-schema-builder.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,11 @@ describe.each(
295295
expect(schemas).toMatchInlineSnapshot(`
296296
"import { z } from "zod/v3"
297297
298-
export const s_AdditionalPropertiesSchema = z.record(s_NamedNullableStringEnum)
299-
300298
export const s_NamedNullableStringEnum = z
301299
.enum(["", "one", "two", "three"])
302-
.nullable()"
300+
.nullable()
301+
302+
export const s_AdditionalPropertiesSchema = z.record(s_NamedNullableStringEnum)"
303303
`)
304304
})
305305

@@ -1477,7 +1477,7 @@ describe.each(
14771477
},
14781478
config,
14791479
)
1480-
expect(code).toMatchInlineSnapshot(`"const x = z.object({})"`)
1480+
expect(code).toMatchInlineSnapshot('"const x = z.object({})"')
14811481
await expect(execute({any: "object"})).resolves.toEqual({})
14821482
await expect(execute("some string")).rejects.toThrow(
14831483
"Expected object, received string",
@@ -1575,7 +1575,7 @@ describe.each(
15751575
},
15761576
config,
15771577
)
1578-
expect(code).toMatchInlineSnapshot(`"const x = z.object({})"`)
1578+
expect(code).toMatchInlineSnapshot('"const x = z.object({})"')
15791579
await expect(execute({any: "object"})).resolves.toEqual({})
15801580
await expect(execute("some string")).rejects.toThrow(
15811581
"Expected object, received string",

packages/openapi-code-generator/src/typescript/common/schema-builders/zod-v4-schema-builder.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,14 @@ describe.each(
296296
expect(schemas).toMatchInlineSnapshot(`
297297
"import { z } from "zod/v4"
298298
299+
export const s_NamedNullableStringEnum = z
300+
.enum(["", "one", "two", "three"])
301+
.nullable()
302+
299303
export const s_AdditionalPropertiesSchema = z.record(
300304
z.string(),
301305
s_NamedNullableStringEnum,
302-
)
303-
304-
export const s_NamedNullableStringEnum = z
305-
.enum(["", "one", "two", "three"])
306-
.nullable()"
306+
)"
307307
`)
308308
})
309309

@@ -1502,7 +1502,7 @@ describe.each(
15021502
},
15031503
config,
15041504
)
1505-
expect(code).toMatchInlineSnapshot(`"const x = z.object({})"`)
1505+
expect(code).toMatchInlineSnapshot('"const x = z.object({})"')
15061506
await expect(execute({any: "object"})).resolves.toEqual({})
15071507
await expect(execute("some string")).rejects.toThrow(
15081508
"Invalid input: expected object, received string",
@@ -1602,7 +1602,7 @@ describe.each(
16021602
},
16031603
config,
16041604
)
1605-
expect(code).toMatchInlineSnapshot(`"const x = z.object({})"`)
1605+
expect(code).toMatchInlineSnapshot('"const x = z.object({})"')
16061606
await expect(execute({any: "object"})).resolves.toEqual({})
16071607
await expect(execute("some string")).rejects.toThrow(
16081608
"Invalid input: expected object, received string",

0 commit comments

Comments
 (0)