Skip to content

Commit e5df4aa

Browse files
committed
Fix tuples crash
1 parent 8c7a8d1 commit e5df4aa

File tree

7 files changed

+58
-3
lines changed

7 files changed

+58
-3
lines changed

lib/typelizer/interface.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def self_type_name
177177
end
178178

179179
def extract_typescript_types(type)
180-
type.split(/[<>\[\],\s|]+/)
180+
type.split(/[<>\[\],\s|]+/).reject(&:empty?)
181181
end
182182

183183
def global_type?(type)

lib/typelizer/openapi.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def v31?(openapi_version)
203203
end
204204

205205
def ts_only_type?(type_str)
206-
type_str.start_with?("{") || type_str.include?("<") || TS_OBJECT_TYPES.include?(type_str)
206+
type_str.start_with?("{", "[") || type_str.include?("<") || TS_OBJECT_TYPES.include?(type_str)
207207
end
208208

209209
def validate_version!(openapi_version)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"username": {
5+
"type": "string"
6+
},
7+
"coordinates": {
8+
"type": "object"
9+
}
10+
},
11+
"required": [
12+
"username",
13+
"coordinates"
14+
]
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"username": {
5+
"type": "string"
6+
},
7+
"coordinates": {
8+
"type": "object"
9+
}
10+
},
11+
"required": [
12+
"username",
13+
"coordinates"
14+
]
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Typelizer digest 472a2113fcda840c96020c17180bddc5
2+
//
3+
// DO NOT MODIFY: This file was automatically generated by Typelizer.
4+
5+
type AlbaTupleType = {
6+
username: string;
7+
coordinates: [number, string];
8+
}
9+
10+
export default AlbaTupleType;

spec/__snapshots__/index.ts.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Typelizer digest 3c012129efae87bd01e4f32b9780a34f
1+
// Typelizer digest 19881c98a46bcfd3a0e991aa8a7eb7cf
22
//
33
// DO NOT MODIFY: This file was automatically generated by Typelizer.
44
export type { AdminRole, PostCategory, UserRole } from './Enums'
@@ -30,6 +30,7 @@ export type { default as AlbaSorted } from './AlbaSorted'
3030
export type { default as AlbaTraitsAssociations, AlbaTraitsAssociationsAssociationsTrait, AlbaTraitsAssociationsWithPostsTrait, AlbaTraitsAssociationsFullTrait, AlbaTraitsAssociationsWithAliasedAssociationsTrait } from './AlbaTraitsAssociations'
3131
export type { default as AlbaTraits, AlbaTraitsBasicTrait, AlbaTraitsTimeRelatedTrait, AlbaTraitsComplexTrait, AlbaTraitsCustomAttributesTrait, AlbaTraitsWithOptionsTrait, AlbaTraitsMixedTrait, AlbaTraitsEmptyTrait } from './AlbaTraits'
3232
export type { default as AlbaTransformKeys } from './AlbaTransformKeys'
33+
export type { default as AlbaTupleType } from './AlbaTupleType'
3334
export type { default as AlbaTypeShortcuts, AlbaTypeShortcutsWithMetadataTrait } from './AlbaTypeShortcuts'
3435
export type { default as AlbaUnionSorted } from './AlbaUnionSorted'
3536
export type { default as AlbaUserAuthor } from './AlbaUserAuthor'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
module Alba
4+
class TupleTypeSerializer < BaseSerializer
5+
typelize_from ::User
6+
7+
attributes :username
8+
9+
typelize "[number, string]"
10+
attribute :coordinates do |user|
11+
[1, "hello"]
12+
end
13+
end
14+
end

0 commit comments

Comments
 (0)