Skip to content

Commit

Permalink
Merge pull request #712 from swagger-api/fix_pattern_2_0
Browse files Browse the repository at this point in the history
fix pattern deserializer
  • Loading branch information
gracekarina committed May 16, 2018
2 parents 43e5f4f + b43f5d9 commit 3fbab89
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
}

String pattern = getString("pattern", node, false, location, result);
if (StringUtils.isNotBlank(value)) {
if (StringUtils.isNotBlank(pattern)) {
schema.setPattern(pattern);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ public void issue682() throws Exception {
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 {
Expand Down
33 changes: 33 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/testPattern.yaml
Original file line number Diff line number Diff line change
@@ -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]+$

0 comments on commit 3fbab89

Please sign in to comment.