Skip to content

Commit

Permalink
Merge pull request #413 from RepreZen/task/410
Browse files Browse the repository at this point in the history
[#410] References to path items are not treated correctly
  • Loading branch information
tfesenko committed Oct 11, 2017
2 parents 1b00a0d + affb1ed commit 233a5e5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import static com.reprezen.swagedit.core.model.NodeDeserializer.ATTRIBUTE_POINTER;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -223,6 +225,12 @@ public AbstractNode find(String pointer) {
pointer = pointer.substring(0, pointer.length() - 1);
}

try {
pointer = URLDecoder.decode(pointer, "UTF-8");
} catch (UnsupportedEncodingException e) {
// leave the pointer as it is
}

try {
return nodes.get(JsonPointer.valueOf(pointer));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,20 @@ class ReferenceValidatorTest {
/foo/{bar}:
get:
parameters:
- $ref: '#/paths/~1foo~1%7Bbar%7D'
- $ref: '#/components/parameters/bar'
responses:
'200':
description: OK
components:
parameters:
bar:
name: bar
in: path
'''

document.set(content)
val baseURI = new URI(null, null, null)
val resolvedURI = new URI(null, null, "/paths/~1foo~1{bar}")
val resolvedURI = new URI(null, null, "/components/parameters/bar")
val errors = validator(#{resolvedURI -> document.asJson}).validate(baseURI, document)

assertEquals(0, errors.size())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,32 @@ class ValidatorTest {
assertThat(errors.map[line], hasItems(9))
}

@Test
def void testPointerWithSpecialCharacters() {
val content = '''
openapi: "3.0.0"
info:
version: "1.0.0"
title: Test API
paths:
/test/{id}:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/paths/~1test~1%7Bid%7D"
'''

document.set(content)
val errors = validator.validate(document, null as URI)
assertEquals(1, errors.size())
assertTrue(errors.map[message].forall[it.equals(Messages.error_invalid_reference_type)])
assertThat(errors.map[line], hasItems(14))
}

private def shouldHaveInvalidReferenceType(String actual) {
expectedMessage(Messages.error_invalid_reference_type + " It should be a valid security scheme.").apply(actual)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,19 @@ class ReferenceValidatorTest {
/foo/{bar}:
get:
parameters:
- $ref: '#/paths/~1foo~1%7Bbar%7D'
- $ref: '#/parameters/bar'
responses:
'200':
description: OK
parameters:
bar:
name: bar
in: path
'''

document.set(content)
val baseURI = new URI(null, null, null)
val resolvedURI = new URI(null, null, "/paths/~1foo~1{bar}")
val resolvedURI = new URI(null, null, "/parameters/bar")
val errors = validator(#{resolvedURI -> document.asJson}).validate(baseURI, document)

assertEquals(0, errors.size())
Expand Down

0 comments on commit 233a5e5

Please sign in to comment.