Skip to content

Commit 233a5e5

Browse files
authored
Merge pull request #413 from RepreZen/task/410
[#410] References to path items are not treated correctly
2 parents 1b00a0d + affb1ed commit 233a5e5

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
@@ -696,6 +696,32 @@ class ValidatorTest {
696696
assertThat(errors.map[line], hasItems(9))
697697
}
698698

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

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)