File tree 5 files changed +53
-12
lines changed
modules/swagger-codegen/src/main/java/io/swagger/codegen 5 files changed +53
-12
lines changed Original file line number Diff line number Diff line change @@ -122,11 +122,20 @@ public static void main(String[] args) {
122
122
123
123
public static List <CodegenConfig > getExtensions () {
124
124
ServiceLoader <CodegenConfig > loader = ServiceLoader .load (CodegenConfig .class );
125
- List <CodegenConfig > output = new ArrayList <CodegenConfig >();
126
- for (CodegenConfig aLoader : loader ) {
127
- output .add (aLoader );
125
+ Map <String , CodegenConfig > output = new HashMap <>();
126
+
127
+ for (CodegenConfig config : loader ) {
128
+ if (output .get (config .getName ()) == null ) {
129
+ output .put (config .getName (), config );
130
+ } else if (config .isPrivileged () && !output .get (config .getName ()).isPrivileged ()) {
131
+ output .put (config .getName (), config );
132
+ } else if (output .get (config .getName ()).isPrivileged () && !config .isPrivileged ()) {
133
+ // skip
134
+ } else if (config .getPriority () > output .get (config .getName ()).getPriority ()) {
135
+ output .put (config .getName (), config );
136
+ }
128
137
}
129
- return output ;
138
+ return new ArrayList <>( output . values ()) ;
130
139
}
131
140
132
141
static void usage (Options options ) {
Original file line number Diff line number Diff line change @@ -239,4 +239,16 @@ public interface CodegenConfig {
239
239
boolean defaultIgnoreImportMappingOption ();
240
240
241
241
boolean isUsingFlattenSpec ();
242
+
243
+ default boolean isPrivileged () {
244
+ return false ;
245
+ }
246
+
247
+ default int getPriority () {
248
+ return Integer .MIN_VALUE ;
249
+ }
250
+
251
+ default String getCodeName () {
252
+ return getName ();
253
+ }
242
254
}
Original file line number Diff line number Diff line change @@ -15,14 +15,25 @@ public static CodegenConfig forName(String name) {
15
15
ServiceLoader <CodegenConfig > loader = load (CodegenConfig .class );
16
16
17
17
StringBuilder availableConfigs = new StringBuilder ();
18
-
18
+ CodegenConfig current = null ;
19
19
for (CodegenConfig config : loader ) {
20
+
20
21
if (config .getName ().equals (name )) {
21
- return config ;
22
+ if (current == null ) {
23
+ current = config ;
24
+ } else if (config .isPrivileged () && !current .isPrivileged ()) {
25
+ current = config ;
26
+ } else if (current .isPrivileged () && !config .isPrivileged ()) {
27
+ // skip
28
+ } else if (config .getPriority () > current .getPriority ()) {
29
+ current = config ;
30
+ }
22
31
}
23
-
24
32
availableConfigs .append (config .getName ()).append ("\n " );
25
33
}
34
+ if (current != null ) {
35
+ return current ;
36
+ }
26
37
27
38
// else try to load directly
28
39
try {
Original file line number Diff line number Diff line change @@ -39,11 +39,20 @@ public static void main(String[] args) {
39
39
40
40
public static List <CodegenConfig > getExtensions () {
41
41
ServiceLoader <CodegenConfig > loader = ServiceLoader .load (CodegenConfig .class );
42
- List <CodegenConfig > output = new ArrayList <CodegenConfig >();
42
+ Map <String , CodegenConfig > output = new HashMap <>();
43
+
43
44
for (CodegenConfig config : loader ) {
44
- output .add (config );
45
+ if (output .get (config .getName ()) == null ) {
46
+ output .put (config .getName (), config );
47
+ } else if (config .isPrivileged () && !output .get (config .getName ()).isPrivileged ()) {
48
+ output .put (config .getName (), config );
49
+ } else if (output .get (config .getName ()).isPrivileged () && !config .isPrivileged ()) {
50
+ // skip
51
+ } else if (config .getPriority () > output .get (config .getName ()).getPriority ()) {
52
+ output .put (config .getName (), config );
53
+ }
45
54
}
46
- return output ;
55
+ return new ArrayList <>( output . values ()) ;
47
56
}
48
57
49
58
static void usage (Options options ) {
Original file line number Diff line number Diff line change 1058
1058
</repositories >
1059
1059
<properties >
1060
1060
<maven .compiler.release>8</maven .compiler.release>
1061
- <swagger-parser-version >1.0.70 </swagger-parser-version >
1061
+ <swagger-parser-version >1.0.71 </swagger-parser-version >
1062
1062
<scala-version >2.11.1</scala-version >
1063
1063
<felix-version >3.3.0</felix-version >
1064
1064
<swagger-core-version >1.6.14</swagger-core-version >
1075
1075
Codegen support of Java 8 should be removed if updating to 1.16+
1076
1076
-->
1077
1077
<jmustache-version >1.15</jmustache-version >
1078
- <testng-version >7.10.1 </testng-version >
1078
+ <testng-version >7.10.2 </testng-version >
1079
1079
<surefire-version >3.0.0</surefire-version >
1080
1080
<jmockit-version >1.49</jmockit-version >
1081
1081
<mockito-version >5.11.0</mockito-version >
You can’t perform that action at this time.
0 commit comments