Skip to content

Commit 8e24133

Browse files
authored
chore(python): support Stacks, Templates in generator (#41)
1 parent d9c6636 commit 8e24133

File tree

6 files changed

+111
-3
lines changed

6 files changed

+111
-3
lines changed

openapi-generator/src/main/java/com/influxdb/codegen/InfluxCSharpGenerator.java

+6
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ public boolean usesOwnAuthorizationSchema()
215215
return false;
216216
}
217217

218+
@Override
219+
public boolean supportsStacksTemplates()
220+
{
221+
return false;
222+
}
223+
218224
@NotNull
219225
@Override
220226
public Collection<String> getTypeAdapterImports()

openapi-generator/src/main/java/com/influxdb/codegen/InfluxGenerator.java

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public interface InfluxGenerator
2626

2727
boolean usesOwnAuthorizationSchema();
2828

29+
boolean supportsStacksTemplates();
30+
2931
@Nonnull
3032
Collection<String> getTypeAdapterImports();
3133
}

openapi-generator/src/main/java/com/influxdb/codegen/InfluxJavaGenerator.java

+6
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ public boolean usesOwnAuthorizationSchema()
445445
return false;
446446
}
447447

448+
@Override
449+
public boolean supportsStacksTemplates()
450+
{
451+
return false;
452+
}
453+
448454
@NotNull
449455
@Override
450456
public Collection<String> getTypeAdapterImports()

openapi-generator/src/main/java/com/influxdb/codegen/InfluxPhpGenerator.java

+6
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ public boolean usesOwnAuthorizationSchema()
203203
return true;
204204
}
205205

206+
@Override
207+
public boolean supportsStacksTemplates()
208+
{
209+
return false;
210+
}
211+
206212
@NotNull
207213
@Override
208214
public Collection<String> getTypeAdapterImports()

openapi-generator/src/main/java/com/influxdb/codegen/InfluxPythonGenerator.java

+22
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ public String toApiFilename(String name) {
127127
return StringUtils.underscore(name) + "_service";
128128
}
129129

130+
@Override
131+
public String toVarName(String name)
132+
{
133+
name = name.replaceAll("orgIDs", "orgIds");
134+
135+
return super.toVarName(name);
136+
}
137+
138+
@Override
139+
public String toModelFilename(String name)
140+
{
141+
name = name.replaceAll("orgIDs", "orgIds");
142+
143+
return super.toModelFilename(name);
144+
}
145+
130146
@Override
131147
public void processOpenAPI(OpenAPI openAPI) {
132148

@@ -183,6 +199,12 @@ public boolean usesOwnAuthorizationSchema()
183199
return true;
184200
}
185201

202+
@Override
203+
public boolean supportsStacksTemplates()
204+
{
205+
return true;
206+
}
207+
186208
@NotNull
187209
@Override
188210
public Collection<String> getTypeAdapterImports()

openapi-generator/src/main/java/com/influxdb/codegen/PostProcessHelper.java

+69-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Map;
1212
import java.util.Set;
1313
import java.util.function.BiConsumer;
14+
import java.util.function.Consumer;
1415
import java.util.function.Function;
1516
import java.util.stream.Collectors;
1617
import java.util.stream.Stream;
@@ -187,17 +188,64 @@ void postProcessOpenAPI()
187188
//
188189
{
189190
dropSchemas("Geo(.*)View(.*)");
191+
dropSchemas("LatLon(.*)");
190192
((ComposedSchema) openAPI.getComponents().getSchemas().get("ViewProperties"))
191193
.getOneOf()
192194
.removeIf(schema -> schema.get$ref().endsWith("GeoViewProperties"));
193195
}
194196

195197
//
196-
// Drop supports for Templates, Stack
198+
// Templates, Stack API
197199
//
198200
{
199-
dropSchemas("Stack(.*)|Template(.*)|LatLon(.*)");
200-
dropPaths("/stacks(.*)|/templates(.*)");
201+
// Fix naming for ViewLink and ViewsLink schema
202+
{
203+
Schema viewSchema = openAPI.getComponents().getSchemas().get("View");
204+
Schema links = (Schema) viewSchema.getProperties().get("links");
205+
((Schema) links.getProperties().get("self")).setTitle("ViewLinks");
206+
207+
Schema viewsSchema = openAPI.getComponents().getSchemas().get("Views");
208+
Schema viewsSchemaLinks = (Schema) viewsSchema.getProperties().get("links");
209+
((Schema) viewsSchemaLinks.getProperties().get("self")).setTitle("ViewLinks");
210+
}
211+
212+
// Fix naming for 'new' and 'old' property of TemplateSummary.diff
213+
{
214+
Schema schema = openAPI.getComponents().getSchemas().get("TemplateSummary");
215+
ObjectSchema diff = (ObjectSchema) schema.getProperties().get("diff");
216+
for (Map.Entry<String, Schema> entry : diff.getProperties().entrySet())
217+
{
218+
String path = entry.getKey();
219+
ArraySchema pathSchema = (ArraySchema) entry.getValue();
220+
Schema newSchema = (Schema) pathSchema.getItems().getProperties().get("new");
221+
if (newSchema != null && newSchema.get$ref() == null)
222+
{
223+
newSchema.setTitle("TemplateSummary_Diff_" + path + "_new_old");
224+
}
225+
}
226+
}
227+
228+
// Fix schema name for UpdateStack.additionalResources
229+
{
230+
Schema stackPatch = openAPI.getPaths()
231+
.get("/stacks/{stack_id}")
232+
.getPatch()
233+
.getRequestBody()
234+
.getContent()
235+
.get("application/json")
236+
.getSchema();
237+
Schema additionalResources = ((ArraySchema) stackPatch.getProperties().get("additionalResources"))
238+
.getItems();
239+
additionalResources.setTitle("PatchStackRequest_additionalResources");
240+
}
241+
242+
//
243+
// Drop if not supported
244+
//
245+
if (!generator.supportsStacksTemplates())
246+
{
247+
dropPaths("/stacks(.*)|/templates(.*)");
248+
}
201249
}
202250

203251
//
@@ -304,6 +352,24 @@ void postProcessOpenAPI()
304352
parameter.setDescription(description.trim());
305353
}
306354
});
355+
for (PathItem path : openAPI.getPaths().values())
356+
{
357+
for (Operation operation : path.readOperations())
358+
{
359+
List<Parameter> parameters = operation.getParameters();
360+
if (parameters != null)
361+
{
362+
for (Parameter parameter : parameters)
363+
{
364+
String description = parameter.getDescription();
365+
if (description != null)
366+
{
367+
parameter.setDescription(description.trim());
368+
}
369+
}
370+
}
371+
}
372+
}
307373
}
308374

309375
public void postProcessModel(final CodegenModel model, final Schema modelSchema, final Map<String, Schema> allDefinitions)

0 commit comments

Comments
 (0)