Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(api): puts the api ref into three columns #9531

Merged
merged 9 commits into from
Feb 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public class KafkaClusterSpec implements HasConfigurableMetrics, HasConfigurable
public static final String FORBIDDEN_PREFIXES = "listeners, advertised., broker., listener., host.name, port, "
+ "inter.broker.listener.name, sasl., ssl., security., password., log.dir, "
+ "zookeeper.connect, zookeeper.set.acl, zookeeper.ssl, zookeeper.clientCnxnSocket, authorizer., super.user, "
+ "cruise.control.metrics.topic, cruise.control.metrics.reporter.bootstrap.servers,"
+ "cruise.control.metrics.topic, cruise.control.metrics.reporter.bootstrap.servers, "
+ "node.id, process.roles, controller., metadata.log.dir"; // KRaft options

public static final String FORBIDDEN_PREFIX_EXCEPTIONS = "zookeeper.connection.timeout.ms, sasl.server.max.receive.size,"
+ "ssl.cipher.suites, ssl.protocol, ssl.enabled.protocols, ssl.secure.random.implementation,"
+ "cruise.control.metrics.topic.num.partitions, cruise.control.metrics.topic.replication.factor, cruise.control.metrics.topic.retention.ms,"
+ "cruise.control.metrics.topic.auto.create.retries, cruise.control.metrics.topic.auto.create.timeout.ms,"
+ "cruise.control.metrics.topic.min.insync.replicas,"
public static final String FORBIDDEN_PREFIX_EXCEPTIONS = "zookeeper.connection.timeout.ms, sasl.server.max.receive.size, "
+ "ssl.cipher.suites, ssl.protocol, ssl.enabled.protocols, ssl.secure.random.implementation, "
+ "cruise.control.metrics.topic.num.partitions, cruise.control.metrics.topic.replication.factor, cruise.control.metrics.topic.retention.ms, "
+ "cruise.control.metrics.topic.auto.create.retries, cruise.control.metrics.topic.auto.create.timeout.ms, "
+ "cruise.control.metrics.topic.min.insync.replicas, "
+ "controller.quorum.election.backoff.max.ms, controller.quorum.election.timeout.ms, controller.quorum.fetch.timeout.ms"; // KRaft options

protected Storage storage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import static io.strimzi.crdgenerator.Property.subtypeMap;
import static io.strimzi.crdgenerator.Property.subtypeNames;
import static io.strimzi.crdgenerator.Property.subtypes;
import static java.lang.Integer.max;
import static java.util.Collections.emptySet;
import static java.util.Collections.singletonList;

Expand Down Expand Up @@ -140,62 +139,54 @@ private void appendCommonTypeDoc(Crd crd, Class<?> cls) throws IOException {
appendUsedIn(crd, cls);
appendDescription(cls);
appendDiscriminator(crd, cls);

out.append("[options=\"header\"]").append(NL);
out.append("[cols=\"2,2,3\",options=\"header\"]").append(NL);
out.append("|====").append(NL);
out.append("|Property");
String gunk = "1.2+<.<";
final Map<String, Property> properties = properties(crApiVersion, cls);
int maxLen = computePadding(gunk, properties);
appendRepeated(' ', maxLen - "Property".length() + 1);
out.append("|Description");
out.append(NL);

out.append("|Property |Property type |Description").append(NL);

LinkedHashSet<Class<?>> types = new LinkedHashSet<>();

for (Map.Entry<String, Property> entry: properties.entrySet()) {
for (Map.Entry<String, Property> entry : properties(crApiVersion, cls).entrySet()) {
String propertyName = entry.getKey();
final Property property = entry.getValue();
PropertyType propertyType = property.getType();
out.append("|").append(propertyName);
appendRepeated(' ', maxLen - propertyName.length() - gunk.length());
out.append(' ');
out.append(gunk);
out.append("a|");

// Set warning message for deprecated fields
addDeprecationWarning(property);

// Set the field description
addDescription(cls, property);


// Set the external link to Kubernetes docs or the link for fields distinguished by `type`
KubeLink kubeLink = property.getAnnotation(KubeLink.class);
String externalUrl = linker != null && kubeLink != null ? linker.link(kubeLink) : null;
addExternalUrl(property, kubeLink, externalUrl);


// Add the property name
out.append("|").append(propertyName);

// Add the property type description
appendPropertyType(crd, out, propertyType, externalUrl);

// Set warning message for deprecated fields
addDeprecationWarning(property);

// Add the version the field was added in
addAddedIn(property);

// Add the types to the `types` array to also generate the docs for the type itself
Class<?> documentedType = propertyType.isArray() ? propertyType.arrayBase() : propertyType.getType();

if (externalUrl == null
&& !Schema.isJsonScalarType(documentedType)
&& !documentedType.equals(Map.class)
&& !documentedType.equals(Object.class)) {
&& !Schema.isJsonScalarType(documentedType)
&& !documentedType.equals(Map.class)
&& !documentedType.equals(Object.class)) {
types.add(documentedType);
}

// TODO Minimum?, Maximum?, Pattern?

// Add the property type description
appendPropertyType(crd, out, propertyType, externalUrl);
// Add the property description
addDescription(cls, property);

out.append(NL);
}

out.append("|====").append(NL).append(NL);

appendNestedTypes(crd, types);
}
}

/**
* Sets warning message for deprecated fields
Expand Down Expand Up @@ -250,7 +241,7 @@ private void addAddedIn(Property property) throws IOException {
AddedIn addedIn = property.getAnnotation(AddedIn.class);

if (addedIn != null) {
out.append(" Added in Strimzi " + addedIn.value() + ".");
out.append("Added in Strimzi " + addedIn.value() + ". ");
}
}

Expand Down Expand Up @@ -316,18 +307,14 @@ private void appendNestedTypes(Crd crd, LinkedHashSet<Class<?>> types) throws IO
}
}

private int computePadding(String gunk, Map<String, Property> properties) {
int maxLen = 0;
for (Map.Entry<String, Property> entry: properties.entrySet()) {
maxLen = max(maxLen, entry.getKey().length() + 1 + gunk.length());
}
return maxLen;
}

@SuppressWarnings("unchecked")
private void appendPropertyType(Crd crd, Appendable out, PropertyType propertyType, String externalUrl) throws IOException {
Class<?> propertyClass = propertyType.isArray() ? propertyType.arrayBase() : propertyType.getType();
out.append(NL).append("|");


out.append(NL);
out.append("|");

// Now the type link
if (externalUrl != null) {
out.append(externalUrl).append("[").append(propertyClass.getSimpleName()).append("]");
Expand Down Expand Up @@ -367,7 +354,10 @@ private void appendPropertyType(Crd crd, Appendable out, PropertyType propertyTy
out.append(" of dimension ").append(String.valueOf(dim));
}
}

out.append(NL);
out.append("|");

}

private void appendTypeDeprecation(Crd crd, Class<?> cls) throws IOException {
Expand Down
Loading
Loading