[v2.8]Fix controller generation to add test session to generated controllers #237
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor test session related functions in codegen
The code has been refactored to generalize the function of adding test sessions to different controllers. The functions for importing test session in each controller were renamed and refactored into a unified function, which is now called inside each controller-specific function. This approach aims to reduce code repetition and complexity.
Add session to struct and function in generated files
Expanded the appendSessionToStructInFile function to appendNewlineToBlockInFile, which generalizes line additions to the end of any struct or function block. This update improves code reusability. Utilized this function to add a session to multiple generated interface files.
Add session to struct in management controllers
A new function has been implemented to append a session to a struct in the management controllers. The function reads a file, locates a given struct, and then adds a new session prior to the closing brace of the struct. This change will be beneficial for the management of sessions within the struct.
Refactor import addition function for error handling
Updated the addImport function in codegen/main.go to handle and return errors instead of triggering panic. This change also includes verification of the import path and logic adjustments for adding a new import to the parsed file. These updates ensure more robust and error-resistant code execution.
Add 'session' import to controller files
This commit introduces additional functions to automatically add 'session' imports into controller files. Functions have been added to process and add this import into management, apps, and core controller files specifically. The new functions will walk the respective directory's file-paths and add the specified import to all 'interface.go' files.
Refactor factory method parameter replacement in codegen
The factory methods in the code generator have been refactored. The parameters passed into these methods have been modified to include the timestamp (TS) option. Also, excess white space in the code has been removed to adhere to clean coding principles.