Skip to content
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

fix pattern deserializer #712

Merged
merged 1 commit into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]+$