@@ -82,8 +82,10 @@ public void render(ShapeRenderingContext ctx) throws RenderException {
82
82
83
83
if (operations .isEmpty ()) return ;
84
84
85
- new Client (this , false , operations ).render (ctx );
86
- new Client (this , true , operations ).render (ctx );
85
+ var asBaseClass = "" .equals (name );
86
+
87
+ new Client (this , false , asBaseClass , operations ).render (ctx );
88
+ new Client (this , true , asBaseClass , operations ).render (ctx );
87
89
}
88
90
89
91
private Collection <RequestShape > getOperationsForClient () {
@@ -95,32 +97,37 @@ private String getClientClassName(boolean async, boolean base) {
95
97
return "OpenSearch" + Strings .toPascalCase (name ) + (async ? "Async" : "" ) + "Client" + (base ? "Base" : "" );
96
98
}
97
99
98
- private Type getClientType (boolean async , boolean base ) {
99
- var type = Type .builder ().pkg (getPackageName ()).name (getClientClassName (async , base ));
100
- if (base ) {
101
- type .typeParams (getClientType (async , false ));
102
- }
103
- return type .build ();
100
+ private Type getClientType (boolean async ) {
101
+ return Type .builder ().withPackage (getPackageName ()).withName (getClientClassName (async , false )).build ();
104
102
}
105
103
106
104
private static class Client extends Shape {
107
105
private final boolean async ;
106
+ private final boolean base ;
108
107
private final Collection <RequestShape > operations ;
109
108
110
- private Client (Namespace parent , boolean async , Collection <RequestShape > operations ) {
111
- super (parent , parent .getClientClassName (async , false ), null , "Client for the " + parent .name + " namespace." );
109
+ private Client (Namespace parent , boolean async , boolean base , Collection <RequestShape > operations ) {
110
+ super (parent , parent .getClientClassName (async , base ), null , "Client for the " + parent .name + " namespace." );
112
111
this .async = async ;
112
+ this .base = base ;
113
113
this .operations = operations ;
114
114
}
115
115
116
+ @ Override
117
+ public TypeParameterDiamond getTypeParameters () {
118
+ if (!base ) return null ;
119
+ var thisType = getType ().withTypeParams (Type .builder ().withName ("Self" ).build ());
120
+ return TypeParameterDiamond .builder ()
121
+ .withParams (TypeParameterDefinition .builder ().withName ("Self" ).withExtends (thisType ).build ())
122
+ .build ();
123
+ }
124
+
116
125
@ Override
117
126
public Type getExtendsType () {
118
- switch (parent .name ) {
119
- case "" :
120
- return parent .getClientType (async , true );
121
- default :
122
- return Types .Client .ApiClient (Types .Client .Transport .OpenSearchTransport , getType ());
123
- }
127
+ return Types .Client .ApiClient (
128
+ Types .Client .Transport .OpenSearchTransport ,
129
+ !base ? getType () : Type .builder ().withName ("Self" ).build ()
130
+ );
124
131
}
125
132
126
133
public String getName () {
@@ -139,6 +146,10 @@ public boolean isAsync() {
139
146
return this .async ;
140
147
}
141
148
149
+ public boolean isBase () {
150
+ return this .base ;
151
+ }
152
+
142
153
@ Override
143
154
public String toString () {
144
155
return new ToStringBuilder (this ).append ("type" , getType ()).toString ();
@@ -149,7 +160,7 @@ private static class ClientRef {
149
160
private final String name ;
150
161
151
162
public ClientRef (Namespace namespace , boolean async ) {
152
- this .type = namespace .getClientType (async , false );
163
+ this .type = namespace .getClientType (async );
153
164
this .name = namespace .name ;
154
165
}
155
166
0 commit comments