Skip to content

Commit

Permalink
Fix the duplicated import with multiple same association
Browse files Browse the repository at this point in the history
This commit fixes the case where duplicated types are generated
(which causes error) with more than one association with the
same resource option.
  • Loading branch information
okuramasafumi authored and skryukov committed Oct 7, 2024
1 parent 82a6c62 commit ddf439d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/typelizer/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def imports
.uniq
.reject { |type| global_type?(type) }

custom_type_imports + serializer_types
(custom_type_imports + serializer_types).uniq
end

def inspect
Expand Down
3 changes: 2 additions & 1 deletion spec/__snapshots__/AlbaUser.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Typelizer digest 26603b722342e08a183535283afd6418
// Typelizer digest 9639758a07e00e4992619fbdef2450db
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {AlbaPost} from '@/types'
Expand All @@ -9,6 +9,7 @@ type AlbaUser = {
active: boolean;
invitor: AlbaUser;
posts: Array<AlbaPost>;
latest_post: AlbaPost;
}

export default AlbaUser;
3 changes: 2 additions & 1 deletion spec/__snapshots__/AlbaUserSerializerFoo.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Typelizer digest 859bc62cd130d27f4d44be0fdf719c90
// Typelizer digest c6fb5013c54f52cedcbedeaef1455ff1
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {AlbaUser, AlbaPost} from '@/types'
Expand All @@ -9,6 +9,7 @@ type AlbaUserSerializerFoo = {
active: boolean;
invitor: AlbaUser;
posts: Array<AlbaPost>;
latest_post: AlbaPost;
created_at: string;
}

Expand Down
1 change: 1 addition & 0 deletions spec/app/app/serializers/alba/user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class UserSerializer < BaseSerializer
has_one :invitor, resource: UserSerializer

has_many :posts, resource: PostSerializer
has_one :latest_post, resource: PostSerializer # Duplicated association

class FooSerializer < UserSerializer
typelize_from ::User
Expand Down

0 comments on commit ddf439d

Please sign in to comment.