Skip to content

Conversation

bigbes
Copy link
Collaborator

@bigbes bigbes commented Sep 3, 2025

The gentypes tool was previously limited to generating optional types for local
types that implemented the MarshalMsgpack and UnmarshalMsgpack methods. Thi
made it impossible to generate optional types for types from external modules.

This commit enhances the generator to support third-party types by introducing
the following new flags:

  • -force: To bypass the check for MarshalMsgpack and UnmarshalMsgpack methods.
  • -imports: To add necessary imports for the third-party type and custom functions.
  • -marshal-func: To specify a custom marshal function.
  • -unmarshal-func: To specify a custom unmarshal function.

The generator code has been refactored to use a GenerateOptions struct for
better organization.

Additionally, this commit:

  • Adds a new test case for generating an optional type for uuid.UUID.
  • Updates the README.md with documentation for the new flags and an example.
  • Moves test files to a more appropriate internal/test directory.

Closes #TNTP-3734.

Copilot

This comment was marked as outdated.

@bigbes bigbes force-pushed the bigbes/tntp-3734-gentypes-force branch from 2befa5b to 21009e2 Compare September 3, 2025 11:51
@coveralls
Copy link

coveralls commented Sep 3, 2025

Coverage Status

coverage: 91.616%. remained the same
when pulling ecdf7af on bigbes/tntp-3734-gentypes-force
into 54ff5d9 on master.

Copy link
Collaborator

@oleg-jukovec oleg-jukovec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can actually add these methods if there is a reason for it. We have already been asked for these features:

tarantool/go-tarantool#421

@bigbes bigbes force-pushed the bigbes/tntp-3734-gentypes-force branch 2 times, most recently from 90fa741 to 6ef344a Compare September 3, 2025 19:17
@bigbes bigbes requested a review from Copilot September 3, 2025 19:17
Copilot

This comment was marked as outdated.

@bigbes bigbes changed the title gentypes: option to force generate optional types gentypes: add support for third-party types Sep 3, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extends the gentypes tool to support generating optional types for third-party types. Previously, the tool was limited to generating optional types for local types that implemented MarshalMsgpack and UnmarshalMsgpack methods.

  • Adds support for third-party types with new command-line flags (-force, -imports, -marshal-func, -unmarshal-func)
  • Refactors the generator to use a GenerateOptions struct for better organization
  • Includes comprehensive test coverage for uuid.UUID as an example third-party type

Reviewed Changes

Copilot reviewed 14 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
cmd/gentypes/main.go Adds new CLI flags and logic for handling third-party types
cmd/gentypes/generator/extension.go Refactors GenerateByType to use GenerateOptions struct
cmd/gentypes/generator/type_gen.go.tpl Updates template to support custom marshal/unmarshal functions
cmd/gentypes/flag.go Implements stringListFlag type for handling multiple imports
cmd/gentypes/internal/test/uuid_gen.go Generated optional type for uuid.UUID as test case
README.md Documents new flags and provides usage examples
go.mod Adds github.com/google/uuid dependency

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@bigbes bigbes force-pushed the bigbes/tntp-3734-gentypes-force branch from 6ef344a to e519233 Compare September 3, 2025 19:25
@bigbes
Copy link
Collaborator Author

bigbes commented Sep 3, 2025

@oleg-jukovec I've redone this logic once again :( now it has more examples and has even better support for third-party libraries.

The gentypes tool was previously limited to generating optional types for local
types that implemented the MarshalMsgpack and UnmarshalMsgpack methods. Thi
made it impossible to generate optional types for types from external modules.

This commit enhances the generator to support third-party types by introducing
the following new flags:

* -force: To bypass the check for MarshalMsgpack and UnmarshalMsgpack methods.
* -imports: To add necessary imports for the third-party type and custom functions.
* -marshal-func: To specify a custom marshal function.
* -unmarshal-func: To specify a custom unmarshal function.

The generator code has been refactored to use a GenerateOptions struct for
better organization.

Additionally, this commit:

* Adds a new test case for generating an optional type for uuid.UUID.
* Updates the README.md with documentation for the new flags and an example.
* Moves test files to a more appropriate internal/test directory.

Closes #TNTP-3734.
@bigbes bigbes force-pushed the bigbes/tntp-3734-gentypes-force branch from e519233 to ecdf7af Compare September 4, 2025 12:13
@bigbes bigbes merged commit 87ec22b into master Sep 4, 2025
14 checks passed
@bigbes bigbes deleted the bigbes/tntp-3734-gentypes-force branch September 4, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants