-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output filename customization #200
Conversation
2d3def3
to
fa75c2e
Compare
Codecov Report
@@ Coverage Diff @@
## main #200 +/- ##
=======================================
Coverage 98.64% 98.64%
=======================================
Files 52 52
Lines 1840 1841 +1
=======================================
+ Hits 1815 1816 +1
Misses 9 9
Partials 16 16
Flags with carried forward coverage won't be shown. Click here to find out more.
|
fa75c2e
to
50a21a4
Compare
Qodana for .NETIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
67ffe12
to
b608c62
Compare
In the JsonSerializer class, I've added the setting `PropertyNamingPolicy = JsonNamingPolicy.CamelCase` to the JsonSerializerOptions object. The change is to ensure the serialized JSON adheres to the camel case naming convention. This convention is a common standard in JSON data exchange and makes the serialized data more manageable in client apps, such as JavaScript which typically use camel case naming.
Removed JsonPropertyName attributes from properties in various settings classes. These attributes were unnecessary because the Newtonsoft.Json package automatically infers the JsonPropertyName from the property name and they were adding redundancy.
This commit introduces a new property, OutputFilename, to the RefitGeneratorSettings class. This allows users to optionally set the name of the file generated by the Refit library. This flexibility was added to meet diverse user preferences and requirements for file naming.
The filename in the RefitterSourceGenerator has been moved from the initial file read into the subsequent try block. The change improves the code readability and flow, by keeping the file output manipulation logic in one place. It also allows the filename to leverage the OutputFilename setting if it's provided, providing more flexible file naming.
The SwaggerPetstoreCustomOutputFolder.g.cs file was deleted and recreated as CustomGenerated.cs. This change was made to provide better clarity and organization to the auto-generated files structure in the CustomGenerated directory. The SwaggerPetstoreCustomOutputFolder.refitter configuration file was also updated to reflect this new output file name.
The code was modified to allow users more control over output path configuration in RefitGenerator. Now, users can define the output folder and filename either directly with --output or via 'outputFolder' and 'outputFilename' settings in the file. A validation error will be returned if both routes are attempted simultaneously. This change offers greater flexibility and security to avoid path-related problems. Default values have also been shifted from being hard coded, to being set as constants within Settings and RefitGeneratorSettings classes.
The check for whether the directory for the output file exists and its creation if it doesn't, was moved. Previously it was checking for a valid directory for settings.OutputPath before calculating the actual output path. Now the directory verification is done after calculating the actual outputPath, ensuring that a directory will always be created for the correct outputPath.
These additional fields were added to petstore.refitter to simplify the refitter configuration. It eliminates the redundancy of specifying the output file path every time in the smoke-tests script. As a result, the refitter call within the smoke-tests script has been adjusted to no longer include the output path. The output file name was also updated in the GenerateAndBuild call to match the petstore.refitter setting.
Changed the file name in the test assertion to match updates in the code generation. This was necessary to reflect new file naming convention which is part of an effort to streamline the code generation process.
This commit decomposes the validation logic previously located in the `GenerateCommand` class, and moves it into its own `SettingsValidator` class for better organization and reusability. This provides a cleaner architecture and easier future maintenance, as now settings validation can be altered independent from command generation logic.
…tion" This commit adds an optional parameter `outputFilename` to the configuration options in the JSON files of `Refitter.SourceGenerator`, `../README` and `Refitter`. The `outputFilename` allows users to specify a name for the output file, with the default being `Output.cs` for the CLI tool. This change was necessary to provide users more flexibility in naming their output files. Additionally, the commit includes updates to the documentation files - `Refitter.SourceGenerator/README`, `../README`, `Refitter/README` and `../docs/docfx_project/articles/refitter-file-format.md` - to explain the new `outputFilename` option. It also adjusts the explanation on `operationNameTemplate` for clarity. Extra explanatory comments were added to `dependencyInjectionSettings` and a new block `codeGeneratorSettings` was included in the `Refitter/README.md` file to give users more control over the generated types and contracts.
Simplified the Validate method in SettingsValidator by removing the unnecessary CommandContext parameter. This change optimizes the method by improving readability and reducing complexity. Passed Settings directly as an argument.
The ValidateFileExistence method in SettingsValidator.cs has been made static. This change was made because the method does not access any instance members and does not depend on specific object state. Making methods that satisfy these criteria static can result in minor performance improvements.
The ValidateOperationNameAndUrl method in SettingsValidator.cs was changed to be static. This was done because the method does not use any instance variables and can be called without an instance of the class. This improves performance and reduces memory footprint.
The method ValidateFileAndOutputSettings in SettingsValidator.cs was changed to be static. This change was made because we found out during code review that this method does not use any instance data, therefore it makes sense to make it static to improve the readability and maintainability of the code.
The method ValidateFilePath in SettingsValidator.cs was changed to static since it doesn't use or change any instance-level state. This promotes good practice and increased efficiency by avoiding unnecessary object instantiation.
The Validate method in SettingsValidator class got changed from an instance method to a static method. This was done to avoid creating unnecessary instances of SettingsValidator when validating settings in GenerateCommand.cs. The related call in GenerateCommand has been modified accordingly.
b608c62
to
91fceb1
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
The changes here allow further customization of the Refitter output filename using the
outputFilename
setting in the.refitter
settings fileThis implements #184