Skip to content

Commit affb1ed

Browse files
committed
[#410] References to path items are not treated correctly
1 parent fe90082 commit affb1ed

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/model/Model.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import static com.reprezen.swagedit.core.model.NodeDeserializer.ATTRIBUTE_POINTER;
1616

1717
import java.io.IOException;
18+
import java.io.UnsupportedEncodingException;
19+
import java.net.URLDecoder;
1820
import java.util.Iterator;
1921
import java.util.LinkedHashMap;
2022
import java.util.List;
@@ -223,6 +225,12 @@ public AbstractNode find(String pointer) {
223225
pointer = pointer.substring(0, pointer.length() - 1);
224226
}
225227

228+
try {
229+
pointer = URLDecoder.decode(pointer, "UTF-8");
230+
} catch (UnsupportedEncodingException e) {
231+
// leave the pointer as it is
232+
}
233+
226234
try {
227235
return nodes.get(JsonPointer.valueOf(pointer));
228236
} catch (Exception e) {

com.reprezen.swagedit.openapi3.tests/src/com/reprezen/swagedit/openapi3/validation/ReferenceValidatorTest.xtend

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,20 @@ class ReferenceValidatorTest {
136136
/foo/{bar}:
137137
get:
138138
parameters:
139-
- $ref: '#/paths/~1foo~1%7Bbar%7D'
139+
- $ref: '#/components/parameters/bar'
140140
responses:
141141
'200':
142142
description: OK
143+
components:
144+
parameters:
145+
bar:
146+
name: bar
147+
in: path
143148
'''
144149

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

150155
assertEquals(0, errors.size())

com.reprezen.swagedit.openapi3.tests/src/com/reprezen/swagedit/openapi3/validation/ValidatorTest.xtend

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,32 @@ class ValidatorTest {
695695
assertThat(errors.map[line], hasItems(9))
696696
}
697697

698+
@Test
699+
def void testPointerWithSpecialCharacters() {
700+
val content = '''
701+
openapi: "3.0.0"
702+
info:
703+
version: "1.0.0"
704+
title: Test API
705+
paths:
706+
/test/{id}:
707+
get:
708+
responses:
709+
'200':
710+
description: OK
711+
content:
712+
application/json:
713+
schema:
714+
$ref: "#/paths/~1test~1%7Bid%7D"
715+
'''
716+
717+
document.set(content)
718+
val errors = validator.validate(document, null as URI)
719+
assertEquals(1, errors.size())
720+
assertTrue(errors.map[message].forall[it.equals(Messages.error_invalid_reference_type)])
721+
assertThat(errors.map[line], hasItems(14))
722+
}
723+
698724
private def shouldHaveInvalidReferenceType(String actual) {
699725
expectedMessage(Messages.error_invalid_reference_type + " It should be a valid security scheme.").apply(actual)
700726
}

com.reprezen.swagedit.tests/src/com/reprezen/swagedit/validation/ReferenceValidatorTest.xtend

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,19 @@ class ReferenceValidatorTest {
122122
/foo/{bar}:
123123
get:
124124
parameters:
125-
- $ref: '#/paths/~1foo~1%7Bbar%7D'
125+
- $ref: '#/parameters/bar'
126126
responses:
127127
'200':
128128
description: OK
129+
parameters:
130+
bar:
131+
name: bar
132+
in: path
129133
'''
130134

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

136140
assertEquals(0, errors.size())

0 commit comments

Comments
 (0)