File tree Expand file tree Collapse file tree 5 files changed +53
-12
lines changed
modules/swagger-codegen/src/main/java/io/swagger/codegen Expand file tree Collapse file tree 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) {
122122
123123 public static List <CodegenConfig > getExtensions () {
124124 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+ }
128137 }
129- return output ;
138+ return new ArrayList <>( output . values ()) ;
130139 }
131140
132141 static void usage (Options options ) {
Original file line number Diff line number Diff line change @@ -239,4 +239,16 @@ public interface CodegenConfig {
239239 boolean defaultIgnoreImportMappingOption ();
240240
241241 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+ }
242254}
Original file line number Diff line number Diff line change @@ -15,14 +15,25 @@ public static CodegenConfig forName(String name) {
1515 ServiceLoader <CodegenConfig > loader = load (CodegenConfig .class );
1616
1717 StringBuilder availableConfigs = new StringBuilder ();
18-
18+ CodegenConfig current = null ;
1919 for (CodegenConfig config : loader ) {
20+
2021 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+ }
2231 }
23-
2432 availableConfigs .append (config .getName ()).append ("\n " );
2533 }
34+ if (current != null ) {
35+ return current ;
36+ }
2637
2738 // else try to load directly
2839 try {
Original file line number Diff line number Diff line change @@ -39,11 +39,20 @@ public static void main(String[] args) {
3939
4040 public static List <CodegenConfig > getExtensions () {
4141 ServiceLoader <CodegenConfig > loader = ServiceLoader .load (CodegenConfig .class );
42- List <CodegenConfig > output = new ArrayList <CodegenConfig >();
42+ Map <String , CodegenConfig > output = new HashMap <>();
43+
4344 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+ }
4554 }
46- return output ;
55+ return new ArrayList <>( output . values ()) ;
4756 }
4857
4958 static void usage (Options options ) {
Original file line number Diff line number Diff line change 10581058 </repositories >
10591059 <properties >
10601060 <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 >
10621062 <scala-version >2.11.1</scala-version >
10631063 <felix-version >3.3.0</felix-version >
10641064 <swagger-core-version >1.6.14</swagger-core-version >
10751075 Codegen support of Java 8 should be removed if updating to 1.16+
10761076 -->
10771077 <jmustache-version >1.15</jmustache-version >
1078- <testng-version >7.10.1 </testng-version >
1078+ <testng-version >7.10.2 </testng-version >
10791079 <surefire-version >3.0.0</surefire-version >
10801080 <jmockit-version >1.49</jmockit-version >
10811081 <mockito-version >5.11.0</mockito-version >
You can’t perform that action at this time.
0 commit comments