use of io.fabric8.java.generator.nodes.JCRObject in project kubernetes-client by fabric8io.
the class CRGeneratorRunner method generate.
public List<WritableCRCompilationUnit> generate(CustomResourceDefinition crd, String basePackageName) {
CustomResourceDefinitionSpec crSpec = crd.getSpec();
String crName = crSpec.getNames().getKind();
String group = crSpec.getGroup();
List<WritableCRCompilationUnit> writableCUs = new ArrayList<>(crSpec.getVersions().size());
for (CustomResourceDefinitionVersion crdv : crSpec.getVersions()) {
String version = crdv.getName();
String pkg = Optional.ofNullable(basePackageName).map(p -> p + "." + version).orElse(version);
AbstractJSONSchema2Pojo specGenerator = null;
String prefix = crName;
if (config.getPrefixStrategy() == Config.Prefix.NEVER) {
prefix = "";
}
JSONSchemaProps spec = crdv.getSchema().getOpenAPIV3Schema().getProperties().get("spec");
if (spec != null) {
String suffix = (config.getSuffixStrategy() != Config.Suffix.NEVER) ? "Spec" : "";
specGenerator = AbstractJSONSchema2Pojo.fromJsonSchema("spec", spec, pkg, prefix, suffix, config);
}
AbstractJSONSchema2Pojo statusGenerator = null;
JSONSchemaProps status = crdv.getSchema().getOpenAPIV3Schema().getProperties().get("status");
if (status != null) {
String suffix = (config.getSuffixStrategy() != Config.Suffix.NEVER) ? "Status" : "";
statusGenerator = AbstractJSONSchema2Pojo.fromJsonSchema("status", status, pkg, prefix, suffix, config);
}
AbstractJSONSchema2Pojo crGenerator = new JCRObject(pkg, crName, group, version, prefix + "Spec", prefix + "Status", specGenerator != null, statusGenerator != null, crdv.getStorage(), crdv.getServed(), config);
List<GeneratorResult.ClassResult> classResults = validateAndAggregate(crGenerator, specGenerator, statusGenerator);
writableCUs.add(new WritableCRCompilationUnit(classResults));
}
return writableCUs;
}
Aggregations