Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/Refitter/SettingsValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,27 @@
{
public static ValidationResult Validate(Settings settings)
{
if (BothSettingsFilesAreEmpty(settings) || BothSettingsFilesArePresent(settings))
if (string.IsNullOrWhiteSpace(settings.OpenApiPath) &&
string.IsNullOrWhiteSpace(settings.SettingsFilePath))
{
return GetValidationErrorForSettingsFiles();
return GetValidationErrorForNoInputNoSettings();
}

return !string.IsNullOrWhiteSpace(settings.SettingsFilePath)
? ValidateFilePath(settings)
: ValidateOperationNameAndUrl(settings);
}

private static bool BothSettingsFilesAreEmpty(Settings settings)
{
return string.IsNullOrWhiteSpace(settings.OpenApiPath) &&
string.IsNullOrWhiteSpace(settings.SettingsFilePath);
}

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / script

Invalid token '}' in a member declaration

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / 👌 Verify build

Invalid token '}' in a member declaration

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / 👌 Verify build

Invalid token '}' in a member declaration

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / 👌 Verify build

Invalid token '}' in a member declaration

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / 👌 Verify build

Invalid token '}' in a member declaration

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / 👌 Verify build

Invalid token '}' in a member declaration

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / 👌 Verify build

Invalid token '}' in a member declaration

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / 👌 Verify build

Invalid token '}' in a member declaration

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / 👌 Verify build

Invalid token '}' in a member declaration

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / 👌 Verify build

Invalid token '}' in a member declaration

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / 👌 Verify build

Invalid token '}' in a member declaration

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / 👌 Verify build

Invalid token '}' in a member declaration

Check failure on line 20 in src/Refitter/SettingsValidator.cs

View workflow job for this annotation

GitHub Actions / 👌 Verify build

Invalid token '}' in a member declaration
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

private static bool BothSettingsFilesArePresent(Settings settings)
private static ValidationResult GetValidationErrorForNoInputNoSettings()
{
return !string.IsNullOrWhiteSpace(settings.OpenApiPath) &&
!string.IsNullOrWhiteSpace(settings.SettingsFilePath);
return ValidationResult.Error(
"You should specify an input URL/file directly " +
"or use specify it in 'openApiPath' from the settings file");
}
Comment on lines +21 to 26

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix grammatical error in user-facing message.

Line 25 contains "or use specify it" which should be "or specify it".

🔎 Apply this diff to correct the grammar:
         return ValidationResult.Error(
             "You should specify an input URL/file directly " +
-            "or use specify it in 'openApiPath' from the settings file");
+            "or specify it in 'openApiPath' from the settings file");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private static ValidationResult GetValidationErrorForNoInputNoSettings()
{
return !string.IsNullOrWhiteSpace(settings.OpenApiPath) &&
!string.IsNullOrWhiteSpace(settings.SettingsFilePath);
return ValidationResult.Error(
"You should specify an input URL/file directly " +
"or use specify it in 'openApiPath' from the settings file");
}
private static ValidationResult GetValidationErrorForNoInputNoSettings()
{
return ValidationResult.Error(
"You should specify an input URL/file directly " +
"or specify it in 'openApiPath' from the settings file");
}
🤖 Prompt for AI Agents
In src/Refitter/SettingsValidator.cs around lines 22 to 27, the user-facing
error message contains a grammatical mistake ("or use specify it"); update the
returned string to replace "or use specify it in 'openApiPath' from the settings
file" with "or specify it in 'openApiPath' in the settings file" (or equivalent
correct phrasing) so the message reads clearly and grammatically correct.


private static ValidationResult GetValidationErrorForSettingsFiles()

private static ValidationResult GetValidationErrorForTwoInputFiles()
{
return ValidationResult.Error(
"You should either specify an input URL/file directly " +
Expand All @@ -41,7 +39,6 @@
{
var json = File.ReadAllText(settings.SettingsFilePath!);
var refitGeneratorSettings = Serializer.Deserialize<RefitGeneratorSettings>(json);
settings.OpenApiPath = refitGeneratorSettings.OpenApiPath;

return ValidateFileAndOutputSettings(settings, refitGeneratorSettings);
}
Expand All @@ -50,6 +47,14 @@
Settings settings,
RefitGeneratorSettings refitGeneratorSettings)
{
if (!string.IsNullOrWhiteSpace(settings.OpenApiPath) &&
!string.IsNullOrWhiteSpace(refitGeneratorSettings.OpenApiPath))
{
return GetValidationErrorForTwoInputFiles();
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

settings.OpenApiPath = refitGeneratorSettings.OpenApiPath;

if (string.IsNullOrWhiteSpace(refitGeneratorSettings.OpenApiPath))
{
return GetValidationErrorForOpenApiPath();
Expand Down
Loading