File tree 4 files changed +52
-10
lines changed
modules/swagger-codegen/src/main/java/io/swagger/codegen/v3
4 files changed +52
-10
lines changed Original file line number Diff line number Diff line change 1
1
package io .swagger .codegen .v3 ;
2
2
3
3
import java .util .ArrayList ;
4
+ import java .util .Collections ;
4
5
import java .util .HashMap ;
5
6
import java .util .List ;
6
7
import java .util .Map ;
@@ -122,11 +123,20 @@ public static void main(String[] args) {
122
123
123
124
public static List <CodegenConfig > getExtensions () {
124
125
ServiceLoader <CodegenConfig > loader = ServiceLoader .load (CodegenConfig .class );
125
- List <CodegenConfig > output = new ArrayList <CodegenConfig >();
126
- for (CodegenConfig aLoader : loader ) {
127
- output .add (aLoader );
126
+ Map <String , CodegenConfig > output = new HashMap <>();
127
+
128
+ for (CodegenConfig config : loader ) {
129
+ if (output .get (config .getName ()) == null ) {
130
+ output .put (config .getName (), config );
131
+ } else if (config .isPrivileged () && !output .get (config .getName ()).isPrivileged ()) {
132
+ output .put (config .getName (), config );
133
+ } else if (output .get (config .getName ()).isPrivileged () && !config .isPrivileged ()) {
134
+ // skip
135
+ } else if (config .getPriority () > output .get (config .getName ()).getPriority ()) {
136
+ output .put (config .getName (), config );
137
+ }
128
138
}
129
- return output ;
139
+ return new ArrayList <>( output . values ()) ;
130
140
}
131
141
132
142
static void usage (Options options ) {
Original file line number Diff line number Diff line change @@ -255,4 +255,16 @@ public interface CodegenConfig {
255
255
default boolean checkAliasModel () {
256
256
return false ;
257
257
}
258
+
259
+ default boolean isPrivileged () {
260
+ return false ;
261
+ }
262
+
263
+ default int getPriority () {
264
+ return Integer .MIN_VALUE ;
265
+ }
266
+
267
+ default String getCodeName () {
268
+ return getName ();
269
+ }
258
270
}
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 @@ -38,11 +38,20 @@ public static void main(String[] args) {
38
38
39
39
public static List <CodegenConfig > getExtensions () {
40
40
ServiceLoader <CodegenConfig > loader = ServiceLoader .load (CodegenConfig .class );
41
- List <CodegenConfig > output = new ArrayList <CodegenConfig >();
41
+ Map <String , CodegenConfig > output = new HashMap <>();
42
+
42
43
for (CodegenConfig config : loader ) {
43
- output .add (config );
44
+ if (output .get (config .getName ()) == null ) {
45
+ output .put (config .getName (), config );
46
+ } else if (config .isPrivileged () && !output .get (config .getName ()).isPrivileged ()) {
47
+ output .put (config .getName (), config );
48
+ } else if (output .get (config .getName ()).isPrivileged () && !config .isPrivileged ()) {
49
+ // skip
50
+ } else if (config .getPriority () > output .get (config .getName ()).getPriority ()) {
51
+ output .put (config .getName (), config );
52
+ }
44
53
}
45
- return output ;
54
+ return new ArrayList <>( output . values ()) ;
46
55
}
47
56
48
57
static void usage (Options options ) {
You can’t perform that action at this time.
0 commit comments