Skip to content

Commit afd8760

Browse files
committed
test: add composite_type_with_int_attribute and update typegen test snapshots
1 parent 09985f3 commit afd8760

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

src/server/templates/python.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ class PythonEnum implements Serializable {
198198
}
199199
}
200200

201+
class PythonDomain implements Serializable {
202+
name: string
203+
py_type: PythonType
204+
205+
constructor(name: string, schema: string, py_type: PythonType) {
206+
this.name = `${formatForPyClassName(schema)}${formatForPyClassName(name)}`
207+
this.py_type = py_type
208+
}
209+
210+
serialize(): string {
211+
return `${this.name}: TypeAlias = ${this.py_type.serialize()}`
212+
}
213+
}
214+
201215
type PythonType = PythonListType | PythonSimpleType
202216

203217
class PythonSimpleType implements Serializable {
@@ -327,6 +341,7 @@ const PY_TYPE_MAP: Record<string, string> = {
327341
bool: 'bool',
328342

329343
// Numbers
344+
int: 'int',
330345
int2: 'int',
331346
int4: 'int',
332347
int8: 'int',

test/server/typegen.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5593,6 +5593,11 @@ test('typegen: go', async () => {
55935593
type PublicCompositeTypeWithDomainAttribute struct {
55945594
Name string \`json:"name"\`
55955595
Score interface{} \`json:"score"\`
5596+
}
5597+
5598+
type PublicCompositeTypeWithIntAttribute struct {
5599+
A interface{} \`json:"a"\`
5600+
B interface{} \`json:"b"\`
55965601
}"
55975602
`)
55985603
})
@@ -6122,6 +6127,14 @@ test('typegen: swift', async () => {
61226127
case Score = "score"
61236128
}
61246129
}
6130+
internal struct CompositeTypeWithIntAttribute: Codable, Hashable, Sendable {
6131+
internal let A: AnyJSON
6132+
internal let B: AnyJSON
6133+
internal enum CodingKeys: String, CodingKey {
6134+
case A = "a"
6135+
case B = "b"
6136+
}
6137+
}
61256138
internal struct CompositeTypeWithRecordAttribute: Codable, Hashable, Sendable {
61266139
internal let Todo: TodosSelect
61276140
internal enum CodingKeys: String, CodingKey {
@@ -6661,6 +6674,14 @@ test('typegen: swift w/ public access control', async () => {
66616674
case Score = "score"
66626675
}
66636676
}
6677+
public struct CompositeTypeWithIntAttribute: Codable, Hashable, Sendable {
6678+
public let A: AnyJSON
6679+
public let B: AnyJSON
6680+
public enum CodingKeys: String, CodingKey {
6681+
case A = "a"
6682+
case B = "b"
6683+
}
6684+
}
66646685
public struct CompositeTypeWithRecordAttribute: Codable, Hashable, Sendable {
66656686
public let Todo: TodosSelect
66666687
public enum CodingKeys: String, CodingKey {
@@ -6699,8 +6720,6 @@ test('typegen: python', async () => {
66996720
67006721
PublicMemeStatus: TypeAlias = Literal["new", "old", "retired"]
67016722
6702-
PublicOneToTen: TypeAlias = int
6703-
67046723
class PublicUsers(BaseModel):
67056724
decimal: Optional[float] = Field(alias="decimal")
67066725
id: int = Field(alias="id")
@@ -6946,7 +6965,11 @@ test('typegen: python', async () => {
69466965
69476966
class PublicCompositeTypeWithDomainAttribute(BaseModel):
69486967
name: str = Field(alias="name")
6949-
score: PublicOneToTen = Field(alias="score")"
6968+
score: PublicOneToTen = Field(alias="score")
6969+
6970+
class PublicCompositeTypeWithIntAttribute(BaseModel):
6971+
a: int = Field(alias="a")
6972+
b: int = Field(alias="b")"
69506973
`)
69516974
})
69526975

0 commit comments

Comments
 (0)