nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: swagger-api/swagger-parser
Pull request #712 (2018-05-16 21:50:05)

fix pattern deserializer
refs #709 


Patch:
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
index 0522881a..3bdeb8f1 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
@@ -1906,7 +1906,7 @@ public class OpenAPIDeserializer {
         }
 
         String pattern = getString("pattern", node, false, location, result);
-        if (StringUtils.isNotBlank(value)) {
+        if (StringUtils.isNotBlank(pattern)) {
             schema.setPattern(pattern);
         }
 


Test patch:
diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
index 69e6e217..13dd389e 100644
--- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
+++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
@@ -72,6 +72,14 @@ public class OpenAPIV3ParserTest {
         Assert.assertTrue(result.getOpenAPI().getPaths().get("/JTasker/startRun").getPost().getRequestBody().getContent().get("application/json").getSchema().getProperties().size() == 2);
     }
 
+    @Test
+    public void testPattern() {
+        final OpenAPI openAPI = new OpenAPIV3Parser().readLocation("testPattern.yaml", null, new ParseOptions()).getOpenAPI();
+
+        Schema s = openAPI.getComponents().getSchemas().get("SomeObj");
+        Assert.assertEquals(s.getPattern(),"^[A-Z]+$"); //ERROR: got null
+    }
+
 
     @BeforeClass
     private void setUpWireMockServer() throws IOException {
diff --git a/modules/swagger-parser-v3/src/test/resources/testPattern.yaml b/modules/swagger-parser-v3/src/test/resources/testPattern.yaml
new file mode 100644
index 00000000..e2a5b23d
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/testPattern.yaml
@@ -0,0 +1,33 @@
+openapi: 3.0.1
+info:
+  title: OpenAPI Test
+  description: Simple test
+  license:
+    name: Apache-2.0
+    url: http://www.apache.org/licenses/LICENSE-2.0.html
+  version: 1.0.0
+servers:
+- url: http://localhost:9999/v2
+paths:
+  /ping:
+    post:
+      tags:
+      - someTag
+      summary: test
+      description: test it
+      operationId: pingOp
+      requestBody:
+        content:
+          application/json:
+            schema:
+              $ref: '#/components/schemas/SomeObj'
+        required: true
+      responses:
+        200:
+          description: OK
+          content: {}
+components:
+  schemas:
+    SomeObj:
+      type: string
+      pattern: ^[A-Z]+$
\ No newline at end of file