[csharp-netcore] fix back slash in regex (#15441)

* fix back slash in regex (csharp-netcore)

* undo add pattern test

* update shasum
This commit is contained in:
William Cheng 2023-05-09 13:52:46 +08:00 committed by GitHub
parent 7bc10b03d0
commit 3cf646cda8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 38 additions and 25 deletions

View File

@ -3,7 +3,7 @@
- filename: "samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools.Test/JSONComposedSchemaTests.cs"
sha256: 054adb6efaff70f492e471cb3e4d628d22cda814906808fd3fcce36ce710b7ee
- filename: "samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools.Test/Api/PetApiTests.cs"
sha256: ff6a5fccd4c026d85fe7232911cda445f5065dcefd03abe258e19af5b28d05c5
sha256: 7dad88554fe630d25c787cae05305d302d5e34ca810aee4fa23f20055f9188e1
- filename: "samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools.Test/linux-logo.png"
sha256: 0a67c32728197e942b13bdda064b73793f12f5c795f1e5cf35a3adf69c973230
# java okhttp gson test files

View File

@ -1628,8 +1628,22 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
return GeneratorLanguage.C_SHARP;
}
@Override
public String toRegularExpression(String pattern) {
return addRegularExpressionDelimiter(pattern);
}
@Override
public String addRegularExpressionDelimiter(String pattern) {
if (StringUtils.isEmpty(pattern)) {
return pattern;
}
if (!pattern.matches("^/.*")) {
return "/" + pattern + "/";
}
return pattern;
}
}

View File

@ -865,7 +865,7 @@ namespace Org.OpenAPITools.Model
}
// PatternWithBackslash (string) pattern
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
if (false == regexPatternWithBackslash.Match(this.PatternWithBackslash).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithBackslash, must match a pattern of " + regexPatternWithBackslash, new [] { "PatternWithBackslash" });

View File

@ -317,7 +317,7 @@ namespace Org.OpenAPITools.Model
}
// PatternWithBackslash (string) pattern
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
if (false == regexPatternWithBackslash.Match(this.PatternWithBackslash).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithBackslash, must match a pattern of " + regexPatternWithBackslash, new [] { "PatternWithBackslash" });

View File

@ -315,7 +315,7 @@ namespace Org.OpenAPITools.Model
}
// PatternWithBackslash (string) pattern
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
if (false == regexPatternWithBackslash.Match(this.PatternWithBackslash).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithBackslash, must match a pattern of " + regexPatternWithBackslash, new [] { "PatternWithBackslash" });

View File

@ -315,7 +315,7 @@ namespace Org.OpenAPITools.Model
}
// PatternWithBackslash (string) pattern
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
if (false == regexPatternWithBackslash.Match(this.PatternWithBackslash).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithBackslash, must match a pattern of " + regexPatternWithBackslash, new [] { "PatternWithBackslash" });

View File

@ -464,7 +464,7 @@ namespace Org.OpenAPITools.Model
}
// PatternWithBackslash (string) pattern
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
if (false == regexPatternWithBackslash.Match(this.PatternWithBackslash).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithBackslash, must match a pattern of " + regexPatternWithBackslash, new [] { "PatternWithBackslash" });

View File

@ -463,7 +463,7 @@ namespace Org.OpenAPITools.Model
}
// PatternWithBackslash (string) pattern
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
if (false == regexPatternWithBackslash.Match(this.PatternWithBackslash).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithBackslash, must match a pattern of " + regexPatternWithBackslash, new [] { "PatternWithBackslash" });

View File

@ -463,7 +463,7 @@ namespace Org.OpenAPITools.Model
}
// PatternWithBackslash (string) pattern
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
if (false == regexPatternWithBackslash.Match(this.PatternWithBackslash).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithBackslash, must match a pattern of " + regexPatternWithBackslash, new [] { "PatternWithBackslash" });

View File

@ -463,7 +463,7 @@ namespace Org.OpenAPITools.Model
}
// PatternWithBackslash (string) pattern
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
if (false == regexPatternWithBackslash.Match(this.PatternWithBackslash).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithBackslash, must match a pattern of " + regexPatternWithBackslash, new [] { "PatternWithBackslash" });

View File

@ -12,6 +12,7 @@ using System;
using System.IO;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using RestSharp;
@ -76,7 +77,7 @@ namespace Org.OpenAPITools.Test
}
public PetApiTests()
{
{
instance = new PetApi();
// create pet
@ -86,7 +87,7 @@ namespace Org.OpenAPITools.Test
PetApi petApi = new PetApi("http://petstore.swagger.io/v2/");
petApi.AddPet(p);
}
/// <summary>
/// Test an instance of PetApi
/// </summary>
@ -96,7 +97,7 @@ namespace Org.OpenAPITools.Test
Assert.IsType<PetApi>(instance);
}
/// <summary>
/// Test AddPet
/// </summary>
@ -107,7 +108,7 @@ namespace Org.OpenAPITools.Test
Pet p = createPet();
instance.AddPet(p);
}
/// <summary>
/// Test DeletePet
/// </summary>
@ -116,7 +117,7 @@ namespace Org.OpenAPITools.Test
{
// no need to test as it'c covered by Cleanup() already
}
/// <summary>
/// Test FindPetsByStatus
/// </summary>
@ -133,7 +134,7 @@ namespace Org.OpenAPITools.Test
Assert.Equal("available", pet.Tags[0].Name);
}
}
/// <summary>
/// Test FindPetsByTags
/// </summary>
@ -144,7 +145,7 @@ namespace Org.OpenAPITools.Test
var response = instance.FindPetsByTags(tags);
Assert.IsType<List<Pet>>(response);
}
/// <summary>
/// Test GetPetById
/// </summary>
@ -244,7 +245,7 @@ namespace Org.OpenAPITools.Test
Assert.Equal(56, response.Category.Id);
Assert.Equal("sample category name2", response.Category.Name);
}
/// <summary>
/// Test UpdatePet
/// </summary>
@ -255,9 +256,9 @@ namespace Org.OpenAPITools.Test
// create pet
Pet p = createPet();
instance.UpdatePet(p);
}
/// <summary>
/// Test UpdatePetWithForm
/// </summary>
@ -283,7 +284,7 @@ namespace Org.OpenAPITools.Test
Pet response2 = petApi.GetPetById(petId);
Assert.Equal("new form name2", response2.Name);
}
/// <summary>
/// Test UploadFile
/// </summary>
@ -300,7 +301,7 @@ namespace Org.OpenAPITools.Test
// using optional parameter syntax introduced at .net 4.0
petApi.UploadFile(petId: petId, file: _imageStream);
}
/// <summary>
/// Test UploadFileWithRequiredFile
/// </summary>
@ -364,7 +365,6 @@ namespace Org.OpenAPITools.Test
at.ArrayOfString = new List<string> { "Something here ..." };
Assert.Equal("{\"array_of_string\":[\"Something here ...\"]}", JsonConvert.SerializeObject(at, _serializerSettings));
}
public void Dispose()
@ -374,5 +374,4 @@ namespace Org.OpenAPITools.Test
petApi.DeletePet(petId, "test key");
}
}
}

View File

@ -463,7 +463,7 @@ namespace Org.OpenAPITools.Model
}
// PatternWithBackslash (string) pattern
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
if (false == regexPatternWithBackslash.Match(this.PatternWithBackslash).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithBackslash, must match a pattern of " + regexPatternWithBackslash, new [] { "PatternWithBackslash" });

View File

@ -448,7 +448,7 @@ namespace Org.OpenAPITools.Model
}
// PatternWithBackslash (string) pattern
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
if (false == regexPatternWithBackslash.Match(this.PatternWithBackslash).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithBackslash, must match a pattern of " + regexPatternWithBackslash, new [] { "PatternWithBackslash" });