forked from opensearch-project/opensearch-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport main] Add support for codegen overrides (opensearch-project…
…#1185) * Add support for codegen overrides * Implement ability to override property type mappings Signed-off-by: Thomas Farr <[email protected]> * Ensure generated code is up-to-date Signed-off-by: Thomas Farr <[email protected]> * Fix license header Signed-off-by: Thomas Farr <[email protected]> * Fix tests Signed-off-by: Thomas Farr <[email protected]> --------- Signed-off-by: Thomas Farr <[email protected]> (cherry picked from commit 9c5d9c1) * spotlessApply Signed-off-by: Thomas Farr <[email protected]> --------- Signed-off-by: Thomas Farr <[email protected]>
- Loading branch information
Showing
19 changed files
with
394 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
java-codegen/src/main/java/org/opensearch/client/codegen/model/overrides/Overrides.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.client.codegen.model.overrides; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import org.opensearch.client.codegen.openapi.JsonPointer; | ||
import org.opensearch.client.codegen.utils.ObjectBuilder; | ||
import org.opensearch.client.codegen.utils.ObjectBuilderBase; | ||
|
||
public class Overrides { | ||
public static final Overrides OVERRIDES = builder().build(); | ||
|
||
@Nonnull | ||
private final Map<JsonPointer, SchemaOverride> schemas; | ||
|
||
private Overrides(Builder builder) { | ||
this.schemas = builder.schemas != null ? Collections.unmodifiableMap(builder.schemas) : Collections.emptyMap(); | ||
} | ||
|
||
@Nonnull | ||
public Optional<SchemaOverride> getSchema(@Nonnull JsonPointer pointer) { | ||
return Optional.ofNullable(schemas.get(pointer)); | ||
} | ||
|
||
@Nonnull | ||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static final class Builder extends ObjectBuilderBase<Overrides, Builder> { | ||
@Nullable | ||
private Map<JsonPointer, SchemaOverride> schemas; | ||
|
||
private Builder() {} | ||
|
||
@Nonnull | ||
@Override | ||
protected Overrides construct() { | ||
return new Overrides(this); | ||
} | ||
|
||
@Nonnull | ||
public Builder withSchemas(@Nonnull Function<SchemaOverride.MapBuilder, ObjectBuilder<Map<JsonPointer, SchemaOverride>>> fn) { | ||
this.schemas = Objects.requireNonNull(fn, "fn must not be null").apply(SchemaOverride.mapBuilder()).build(); | ||
return this; | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...codegen/src/main/java/org/opensearch/client/codegen/model/overrides/PropertyOverride.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.client.codegen.model.overrides; | ||
|
||
import java.util.Optional; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import org.opensearch.client.codegen.model.Type; | ||
import org.opensearch.client.codegen.utils.MapBuilderBase; | ||
import org.opensearch.client.codegen.utils.ObjectBuilderBase; | ||
|
||
public final class PropertyOverride { | ||
@Nullable | ||
private final Type mappedType; | ||
|
||
private PropertyOverride(Builder builder) { | ||
this.mappedType = builder.mappedType; | ||
} | ||
|
||
@Nonnull | ||
public Optional<Type> getMappedType() { | ||
return Optional.ofNullable(mappedType); | ||
} | ||
|
||
@Nonnull | ||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
@Nonnull | ||
public static MapBuilder mapBuilder() { | ||
return new MapBuilder(); | ||
} | ||
|
||
public static final class Builder extends ObjectBuilderBase<PropertyOverride, Builder> { | ||
@Nullable | ||
private Type mappedType; | ||
|
||
private Builder() {} | ||
|
||
@Nonnull | ||
@Override | ||
protected PropertyOverride construct() { | ||
return new PropertyOverride(this); | ||
} | ||
|
||
@Nonnull | ||
public Builder withMappedType(@Nullable Type mappedType) { | ||
this.mappedType = mappedType; | ||
return this; | ||
} | ||
} | ||
|
||
public static final class MapBuilder extends MapBuilderBase<String, PropertyOverride, Builder, MapBuilder> { | ||
private MapBuilder() {} | ||
|
||
@Nonnull | ||
@Override | ||
protected Builder valueBuilder() { | ||
return builder(); | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
java-codegen/src/main/java/org/opensearch/client/codegen/model/overrides/SchemaOverride.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.client.codegen.model.overrides; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import org.opensearch.client.codegen.openapi.JsonPointer; | ||
import org.opensearch.client.codegen.utils.MapBuilderBase; | ||
import org.opensearch.client.codegen.utils.ObjectBuilder; | ||
import org.opensearch.client.codegen.utils.ObjectBuilderBase; | ||
|
||
public final class SchemaOverride { | ||
@Nonnull | ||
private final Map<String, PropertyOverride> properties; | ||
|
||
private SchemaOverride(Builder builder) { | ||
this.properties = builder.properties != null ? Collections.unmodifiableMap(builder.properties) : Collections.emptyMap(); | ||
} | ||
|
||
@Nonnull | ||
public Optional<PropertyOverride> getProperty(@Nonnull String key) { | ||
return Optional.ofNullable(properties.get(key)); | ||
} | ||
|
||
@Nonnull | ||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
@Nonnull | ||
public static MapBuilder mapBuilder() { | ||
return new MapBuilder(); | ||
} | ||
|
||
public static final class Builder extends ObjectBuilderBase<SchemaOverride, Builder> { | ||
@Nullable | ||
private Map<String, PropertyOverride> properties; | ||
|
||
private Builder() {} | ||
|
||
@Nonnull | ||
@Override | ||
protected SchemaOverride construct() { | ||
return new SchemaOverride(this); | ||
} | ||
|
||
@Nonnull | ||
public Builder withProperties(@Nonnull Function<PropertyOverride.MapBuilder, ObjectBuilder<Map<String, PropertyOverride>>> fn) { | ||
this.properties = Objects.requireNonNull(fn, "fn must not be null").apply(PropertyOverride.mapBuilder()).build(); | ||
return this; | ||
} | ||
} | ||
|
||
public static final class MapBuilder extends MapBuilderBase<JsonPointer, SchemaOverride, Builder, MapBuilder> { | ||
private MapBuilder() {} | ||
|
||
@Nonnull | ||
@Override | ||
protected Builder valueBuilder() { | ||
return builder(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.