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

Provide schema name to creator #8834

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.List;
import java.util.Set;
import java.util.TreeMap;
import java.util.function.BiFunction;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SchemaId;
Expand Down Expand Up @@ -78,7 +77,9 @@ protected T createSchema(
final SchemaRegistry registry,
final SpecMilestone effectiveMilestone,
final SpecConfig specConfig) {
return getSchemaCreator(effectiveMilestone).creator.apply(registry, specConfig);
return getSchemaCreator(effectiveMilestone)
.creator
.create(registry, specConfig, schemaId.getSchemaName(registry.getMilestone()));
}

private SchemaProviderCreator<T> getSchemaCreator(final SpecMilestone milestone) {
Expand All @@ -95,8 +96,7 @@ public Set<SpecMilestone> getSupportedMilestones() {
return milestoneToSchemaCreator.keySet();
}

protected record SchemaProviderCreator<T>(
SpecMilestone baseMilestone, BiFunction<SchemaRegistry, SpecConfig, T> creator) {
protected record SchemaProviderCreator<T>(SpecMilestone baseMilestone, SchemaCreator<T> creator) {

@Override
public String toString() {
Expand Down Expand Up @@ -156,8 +156,7 @@ private Builder(final SchemaId<T> schemaId) {
}

public Builder<T> withCreator(
final SpecMilestone milestone,
final BiFunction<SchemaRegistry, SpecConfig, T> creationSchema) {
final SpecMilestone milestone, final SchemaCreator<T> creationSchema) {
checkArgument(
schemaProviderCreators.isEmpty()
|| milestone.isGreaterThan(schemaProviderCreators.getLast().baseMilestone),
Expand Down Expand Up @@ -199,4 +198,9 @@ public BaseSchemaProvider<T> build() {
schemaId, schemaProviderCreators, untilMilestone, alwaysCreateNewSchema);
}
}

@FunctionalInterface
public interface SchemaCreator<T> {
T create(SchemaRegistry registry, SpecConfig specConfig, String schemaName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ boolean isProviderRegistered(final SchemaProvider<?> provider) {

@SuppressWarnings("unchecked")
public <T> T get(final SchemaId<T> schemaId) {
SchemaProvider<T> provider = (SchemaProvider<T>) providers.get(schemaId);
final SchemaProvider<T> provider = (SchemaProvider<T>) providers.get(schemaId);
if (provider == null) {
throw new IllegalArgumentException(
"No provider registered for schema "
Expand Down
Loading