Skip to content

Commit 9362253

Browse files
authored
Merge pull request #1004 from swagger-api/issue-995
refs #995 - fixing discriminator with remote enum reference
2 parents 0f80b5f + c090639 commit 9362253

File tree

5 files changed

+175
-3
lines changed

5 files changed

+175
-3
lines changed

modules/swagger-parser/src/main/java/io/swagger/parser/ResolverCache.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.List;
2929
import java.util.Map;
3030
import java.util.Set;
31+
import java.util.concurrent.ConcurrentHashMap;
3132
import java.util.regex.Matcher;
3233
import java.util.regex.Pattern;
3334

@@ -58,7 +59,7 @@ public class ResolverCache {
5859
/*
5960
a map that stores original external references, and their associated renamed references
6061
*/
61-
private Map<String, String> renameCache = new HashMap<>();
62+
private Map<String, String> renameCache = new ConcurrentHashMap<>();
6263

6364
public ResolverCache(Swagger swagger, List<AuthorizationValue> auths, String parentFileLocation) {
6465
this.swagger = swagger;

modules/swagger-parser/src/main/java/io/swagger/parser/processors/ExternalRefProcessor.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,25 @@ private void processDiscriminator(String discriminator, Map<String, Property> pr
208208
processRefProperty(new RefProperty(RefType.DEFINITION.getInternalPrefix()+name), file);
209209
}
210210
}
211-
212-
211+
}else if (prop.getValue() instanceof RefProperty) {
212+
String ref = ((RefProperty) prop.getValue()).getSimpleRef();
213+
Map<String, String> renameCache = cache.getRenameCache();
214+
for (String key : renameCache.keySet()) {
215+
String value = renameCache.get(key);
216+
if (value.equals(ref)) {
217+
Object resolved = cache.getResolutionCache().get(key);
218+
if(resolved != null) {
219+
if (resolved instanceof ModelImpl) {
220+
ModelImpl schema = (ModelImpl) resolved;
221+
if (schema.getEnum() != null) {
222+
for (String name : schema.getEnum()) {
223+
processRefProperty(new RefProperty(RefType.DEFINITION.getInternalPrefix() + name), file);
224+
}
225+
}
226+
}
227+
}
228+
}
229+
}
213230
}
214231
}
215232
}

modules/swagger-parser/src/test/java/io/swagger/parser/SwaggerParserTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ public void testIssueDefinitionWithDots() {
8282
assertNotNull(swagger);
8383
}
8484

85+
@Test
86+
public void testIssue995() {
87+
Swagger swagger = new SwaggerParser().read("issue-995/digitalExp-Product-Unresolved.yaml");
88+
assertNotNull(swagger);
89+
assertTrue(swagger.getDefinitions().size() == 6);
90+
assertNotNull(swagger.getDefinitions().get("MobileProduct"));
91+
assertNotNull(swagger.getDefinitions().get("FixedVoiceProduct"));
92+
assertNotNull(swagger.getDefinitions().get("InternetProduct"));
93+
}
94+
8595
@Test
8696
public void testIssue927() {
8797
Swagger swagger = new SwaggerParser().read("issue-927/issue-927.yaml");
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
info:
2+
description: "This is a common Domain"
3+
version: "1.0"
4+
title: Common Domain
5+
6+
responses:
7+
8+
400-BadRequest:
9+
x-dox-Since: v10.2
10+
description: Bad Request
11+
schema:
12+
$ref: "#/definitions/ErrorResponse"
13+
14+
definitions:
15+
ErrorResponse:
16+
x-dox-Since: v10.2
17+
type: object
18+
description: |
19+
Response containing descriptive error text, error code
20+
required:
21+
- code
22+
- message
23+
properties:
24+
code:
25+
description: |
26+
The code associated with the error
27+
readOnly: true
28+
type: integer
29+
message:
30+
description: |
31+
The message associated with the error
32+
readOnly: true
33+
type: string
34+
35+
ChannelType:
36+
type: string
37+
enum:
38+
- selfService
39+
- retail
40+
- callCenter
41+
42+
Product:
43+
x-dox-Since: '10.2'
44+
description: |
45+
The respesentation of the product
46+
type: object
47+
discriminator: productType
48+
required:
49+
- productType
50+
x-dox-discriminator-name: NAME
51+
x-dox-discriminator-type:
52+
- MobileProduct
53+
- InternetProduct
54+
- FixedVoiceProduct
55+
properties:
56+
id:
57+
type: string
58+
status:
59+
type: string
60+
name:
61+
type: string
62+
productType:
63+
$ref: '#/definitions/ProductType'
64+
65+
ProductType:
66+
x-dox-Since: '10.2'
67+
description: |
68+
The different type of products
69+
enum:
70+
- MobileProduct
71+
- FixedVoiceProduct
72+
- InternetProduct
73+
74+
MobileProduct:
75+
x-dox-Since: 10.2
76+
description: |
77+
The instance of the mobile product being added.
78+
type: object
79+
allOf:
80+
- $ref: "#/definitions/Product"
81+
- type: object
82+
properties:
83+
sim:
84+
type: string
85+
phoneNumber:
86+
type: string
87+
88+
FixedVoiceProduct:
89+
x-dox-Since: 10.2
90+
description: |
91+
The instance of the fixed voice product being added.
92+
type: object
93+
allOf:
94+
- $ref: "#/definitions/Product"
95+
- type: object
96+
properties:
97+
phoneNumber:
98+
type: string
99+
100+
InternetProduct:
101+
x-dox-Since: 10.2
102+
description: |
103+
The instance of the internet product being added.
104+
type: object
105+
allOf:
106+
- $ref: "#/definitions/Product"
107+
- type: object
108+
properties:
109+
userName:
110+
type: string
111+
speed:
112+
type: string
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
swagger: '2.0'
2+
info:
3+
version: '1.0'
4+
title: 'Product Operation'
5+
description: 'Product Operation'
6+
7+
8+
basePath: /commerce
9+
10+
consumes:
11+
- application/json
12+
produces:
13+
- application/json
14+
15+
paths:
16+
17+
/v1/product/{productId}:
18+
get:
19+
summary: Get the product
20+
description: Get the product
21+
parameters:
22+
- name: productId
23+
in: path
24+
required: true
25+
type: string
26+
responses:
27+
200:
28+
description: OK
29+
schema:
30+
$ref: 'digitalExp-CommonDefinitionDomain.yaml#/definitions/Product'
31+
400:
32+
$ref: 'digitalExp-CommonDefinitionDomain.yaml#/responses/400-BadRequest'

0 commit comments

Comments
 (0)