7
7
import io .swagger .v3 .oas .models .parameters .RequestBody ;
8
8
9
9
import java .util .*;
10
- import java .util .function .Predicate ;
11
- import java .util .stream .Collectors ;
12
10
13
11
import org .apache .commons .lang3 .StringUtils ;
14
- import org .openapitools .codegen .CliOption ;
15
- import org .openapitools .codegen .CodegenConfig ;
16
- import org .openapitools .codegen .CodegenOperation ;
17
- import org .openapitools .codegen .CodegenParameter ;
18
- import org .openapitools .codegen .CodegenType ;
19
- import org .openapitools .codegen .SupportingFile ;
12
+ import org .openapitools .codegen .*;
20
13
import org .openapitools .codegen .languages .PhpClientCodegen ;
21
14
import org .openapitools .codegen .utils .ModelUtils ;
22
15
23
16
public class ElasticClientPhpGenerator extends PhpClientCodegen implements CodegenConfig {
24
17
25
- public static final String GENERATOR_NAME = "elastic-php-client" ;
26
- public static final String HELP_URL = "helpUrl" ;
27
- public static final String COPYRIGHT = "copyright" ;
18
+ public static final String GENERATOR_NAME = "elastic-php-client" ;
19
+ public static final String HELP_URL = "helpUrl" ;
20
+ public static final String COPYRIGHT = "copyright" ;
21
+ public static final String CLIENT_CLASS = "clientClass" ;
22
+ public static final String CLIENT_CLASS_QUALIFIER = "clientClassQualifier" ;
28
23
29
24
public ElasticClientPhpGenerator () {
30
25
super ();
31
26
32
27
cliOptions .add (new CliOption (HELP_URL , "Help URL" ));
33
28
cliOptions .add (new CliOption (COPYRIGHT , "Copyright" ));
29
+ cliOptions .add (new CliOption (CLIENT_CLASS , "Client file" ));
34
30
35
31
this .setTemplateDir (ElasticClientPhpGenerator .GENERATOR_NAME );
36
32
this .setSrcBasePath ("" );
@@ -44,9 +40,17 @@ public ElasticClientPhpGenerator() {
44
40
@ Override
45
41
public void processOpts () {
46
42
super .processOpts ();
43
+
44
+ String clientClass = (String ) additionalProperties .getOrDefault (CLIENT_CLASS , "Client" );
45
+ additionalProperties .put (CLIENT_CLASS , clientClass );
46
+
47
+ if (clientClass .startsWith ("Abstract" )) {
48
+ additionalProperties .put (CLIENT_CLASS_QUALIFIER , "abstract" );
49
+ }
50
+
47
51
this .resetTemplateFiles ();
48
52
49
- supportingFiles .add (new SupportingFile ("Client.mustache" , "" , "Client .php" ));
53
+ supportingFiles .add (new SupportingFile ("Client.mustache" , "" , clientClass . concat ( " .php") ));
50
54
supportingFiles .add (new SupportingFile ("README.mustache" , "" , "README.md" ));
51
55
}
52
56
@@ -67,19 +71,20 @@ public String toApiName(String name) {
67
71
68
72
@ Override
69
73
@ SuppressWarnings ("static-method" )
70
- public void addOperationToGroup (String tag , String resourcePath ,
71
- Operation operation , CodegenOperation baseCo ,
72
- Map <String , List <CodegenOperation >> operations ) {
73
-
74
- getCodegenOperationAliases (operation , baseCo ).forEach (co -> {
74
+ public void addOperationToGroup (String tag , String resourcePath , Operation operation , CodegenOperation co , Map <String , List <CodegenOperation >> operations ) {
75
75
String uniqueName = co .operationId ;
76
-
77
76
co .operationIdLowerCase = uniqueName .toLowerCase (Locale .ROOT );
78
77
co .operationIdCamelCase = org .openapitools .codegen .utils .StringUtils .camelize (uniqueName );
79
78
co .operationIdSnakeCase = org .openapitools .codegen .utils .StringUtils .underscore (uniqueName );
80
79
80
+ if (co .vendorExtensions == null ) {
81
+ co .vendorExtensions = new HashMap <>();
82
+ }
83
+
84
+ co .vendorExtensions .put ("x-operation-scope" , co .vendorExtensions .getOrDefault ("x-operation-scope" , "public" ));
85
+ co .vendorExtensions .put ("x-add-to-documentation" , co .vendorExtensions .getOrDefault ("x-operation-scope" , "public" ).equals ("public" ));
86
+
81
87
operations .put (uniqueName , Arrays .asList (co ));
82
- });
83
88
}
84
89
85
90
@ Override
@@ -150,44 +155,4 @@ private void resetTemplateFiles() {
150
155
151
156
apiTemplateFiles .put ("api.mustache" , ".php" );
152
157
}
153
-
154
- private List <CodegenOperation > getCodegenOperationAliases (Operation operation , CodegenOperation co ) {
155
- List <CodegenOperation > operationsAliases = new ArrayList <>();
156
-
157
- operationsAliases .add (co );
158
-
159
- if (operation .getExtensions () != null && operation .getExtensions ().containsKey ("x-operation-aliases" )) {
160
- Map <String , Map <String , Object >> aliases = (Map <String , Map <String , Object >>) operation .getExtensions ().get ("x-operation-aliases" );
161
- for (Map .Entry <String , Map <String , Object >> alias : aliases .entrySet ()) {
162
- CodegenOperation aliasCo = new CodegenOperation ();
163
- List <String > validParamNames = (List ) alias .getValue ().get ("params" );
164
- Predicate <CodegenParameter > paramFilter = codegenParameter -> validParamNames .contains (codegenParameter .paramName );
165
- Arrays .asList (CodegenOperation .class .getFields ()).stream ().forEach (f -> {
166
- try {
167
- Object fieldValue = f .get (co );
168
- if (f .getName ().endsWith ("Params" ) && fieldValue instanceof List ) {
169
- List <CodegenParameter > params = (List <CodegenParameter >) ((List ) fieldValue ).stream ().filter (paramFilter ).map (
170
- p -> ReflectionClone .clone (p , new CodegenParameter ())
171
- ).collect (Collectors .toList ());
172
-
173
- if (params .isEmpty () == false ) {
174
- params .get (params .size () -1 ).hasMore = false ;
175
- }
176
- fieldValue = params ;
177
- }
178
- f .set (aliasCo , fieldValue );
179
- } catch (IllegalAccessException e ) {
180
- ;
181
- }
182
- aliasCo .operationId = alias .getKey ();
183
- if (alias .getValue ().containsKey ("summary" )) {
184
- aliasCo .summary = (String ) alias .getValue ().get ("summary" );
185
- }
186
- });
187
- operationsAliases .add (aliasCo );
188
- }
189
- }
190
-
191
- return operationsAliases ;
192
- }
193
158
}
0 commit comments