All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.emm035.openapi.immutables.v3.parameters.PathParameter Maven / Gradle / Ivy

package io.github.emm035.openapi.immutables.v3.parameters;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.primitives.Booleans;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.github.emm035.openapi.immutables.v3.examples.Example;
import io.github.emm035.openapi.immutables.v3.references.Referenceable;
import io.github.emm035.openapi.immutables.v3.schemas.Schema;
import io.github.emm035.openapi.immutables.v3.shared.Deprecatable;
import io.github.emm035.openapi.immutables.v3.shared.Describable;
import io.github.emm035.openapi.immutables.v3.shared.Extensible;
import io.github.emm035.openapi.immutables.v3.shared.WithMultipleExamples;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

/**
 * Immutable implementation of {@link AbstractPathParameter}.
 * 

* Use the builder to create immutable instances: * {@code PathParameter.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Immutable @CheckReturnValue public final class PathParameter extends AbstractPathParameter { private final Parameter.Location in; private final @Nullable Boolean required; private final @Nullable AbstractPathParameter.Style style; private final @Nullable Boolean explode; private final boolean requiredOrDefault; private final AbstractPathParameter.Style styleOrDefault; private final boolean explodeOrDefault; private final String name; private final Referenceable schema; private final @Nullable Object getDefault; private final ImmutableMap examples; private final @Nullable Boolean deprecated; private final @Nullable String description; private final ImmutableMap extensions; private final boolean referential; private PathParameter( @Nullable Boolean required, @Nullable AbstractPathParameter.Style style, @Nullable Boolean explode, String name, Referenceable schema, @Nullable Object getDefault, ImmutableMap examples, @Nullable Boolean deprecated, @Nullable String description, ImmutableMap extensions) { this.required = required; this.style = style; this.explode = explode; this.name = name; this.schema = schema; this.getDefault = getDefault; this.examples = examples; this.deprecated = deprecated; this.description = description; this.extensions = extensions; this.in = initShim.getIn(); this.requiredOrDefault = initShim.getRequiredOrDefault(); this.styleOrDefault = initShim.getStyleOrDefault(); this.explodeOrDefault = initShim.getExplodeOrDefault(); this.referential = initShim.isReferential(); this.initShim = null; } private static final int STAGE_INITIALIZING = -1; private static final int STAGE_UNINITIALIZED = 0; private static final int STAGE_INITIALIZED = 1; private transient volatile InitShim initShim = new InitShim(); private final class InitShim { private Parameter.Location in; private int inBuildStage; Parameter.Location getIn() { if (inBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (inBuildStage == STAGE_UNINITIALIZED) { inBuildStage = STAGE_INITIALIZING; this.in = Objects.requireNonNull(PathParameter.super.getIn(), "in"); inBuildStage = STAGE_INITIALIZED; } return this.in; } private boolean requiredOrDefault; private int requiredOrDefaultBuildStage; boolean getRequiredOrDefault() { if (requiredOrDefaultBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (requiredOrDefaultBuildStage == STAGE_UNINITIALIZED) { requiredOrDefaultBuildStage = STAGE_INITIALIZING; this.requiredOrDefault = PathParameter.super.getRequiredOrDefault(); requiredOrDefaultBuildStage = STAGE_INITIALIZED; } return this.requiredOrDefault; } private AbstractPathParameter.Style styleOrDefault; private int styleOrDefaultBuildStage; AbstractPathParameter.Style getStyleOrDefault() { if (styleOrDefaultBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (styleOrDefaultBuildStage == STAGE_UNINITIALIZED) { styleOrDefaultBuildStage = STAGE_INITIALIZING; this.styleOrDefault = Objects.requireNonNull(PathParameter.super.getStyleOrDefault(), "styleOrDefault"); styleOrDefaultBuildStage = STAGE_INITIALIZED; } return this.styleOrDefault; } private boolean explodeOrDefault; private int explodeOrDefaultBuildStage; boolean getExplodeOrDefault() { if (explodeOrDefaultBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (explodeOrDefaultBuildStage == STAGE_UNINITIALIZED) { explodeOrDefaultBuildStage = STAGE_INITIALIZING; this.explodeOrDefault = PathParameter.super.getExplodeOrDefault(); explodeOrDefaultBuildStage = STAGE_INITIALIZED; } return this.explodeOrDefault; } private boolean referential; private int referentialBuildStage; boolean isReferential() { if (referentialBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (referentialBuildStage == STAGE_UNINITIALIZED) { referentialBuildStage = STAGE_INITIALIZING; this.referential = PathParameter.super.isReferential(); referentialBuildStage = STAGE_INITIALIZED; } return this.referential; } private String formatInitCycleMessage() { ArrayList attributes = Lists.newArrayList(); if (inBuildStage == STAGE_INITIALIZING) attributes.add("in"); if (requiredOrDefaultBuildStage == STAGE_INITIALIZING) attributes.add("requiredOrDefault"); if (styleOrDefaultBuildStage == STAGE_INITIALIZING) attributes.add("styleOrDefault"); if (explodeOrDefaultBuildStage == STAGE_INITIALIZING) attributes.add("explodeOrDefault"); if (referentialBuildStage == STAGE_INITIALIZING) attributes.add("referential"); return "Cannot build PathParameter, attribute initializers form cycle" + attributes; } } /** * @return The computed-at-construction value of the {@code in} attribute */ @JsonProperty("in") @Override public Parameter.Location getIn() { InitShim shim = this.initShim; return shim != null ? shim.getIn() : this.in; } /** * @return The value of the {@code required} attribute */ @JsonProperty("required") @Override public Optional getRequired() { return Optional.ofNullable(required); } /** * @return The value of the {@code style} attribute */ @JsonProperty("style") @Override public Optional getStyle() { return Optional.ofNullable(style); } /** * @return The value of the {@code explode} attribute */ @JsonProperty("explode") @Override public Optional getExplode() { return Optional.ofNullable(explode); } /** * @return The computed-at-construction value of the {@code requiredOrDefault} attribute */ @JsonProperty("requiredOrDefault") @JsonIgnore @Override public boolean getRequiredOrDefault() { InitShim shim = this.initShim; return shim != null ? shim.getRequiredOrDefault() : this.requiredOrDefault; } /** * @return The computed-at-construction value of the {@code styleOrDefault} attribute */ @JsonProperty("styleOrDefault") @JsonIgnore @Override public AbstractPathParameter.Style getStyleOrDefault() { InitShim shim = this.initShim; return shim != null ? shim.getStyleOrDefault() : this.styleOrDefault; } /** * @return The computed-at-construction value of the {@code explodeOrDefault} attribute */ @JsonProperty("explodeOrDefault") @JsonIgnore @Override public boolean getExplodeOrDefault() { InitShim shim = this.initShim; return shim != null ? shim.getExplodeOrDefault() : this.explodeOrDefault; } /** * @return The value of the {@code name} attribute */ @JsonProperty("name") @Override public String getName() { return name; } /** * @return The value of the {@code schema} attribute */ @JsonProperty("schema") @Override public Referenceable getSchema() { return schema; } /** * @return The value of the {@code getDefault} attribute */ @JsonProperty("default") @Override public Optional getDefault() { return Optional.ofNullable(getDefault); } /** * @return The value of the {@code examples} attribute */ @JsonProperty("examples") @JsonInclude(JsonInclude.Include.NON_EMPTY) @Override public ImmutableMap getExamples() { return examples; } /** * @return The value of the {@code deprecated} attribute */ @JsonProperty("deprecated") @Override public Optional getDeprecated() { return Optional.ofNullable(deprecated); } /** * @return The value of the {@code description} attribute */ @JsonProperty("description") @Override public Optional getDescription() { return Optional.ofNullable(description); } /** * @return The value of the {@code extensions} attribute */ @JsonProperty("extensions") @JsonAnyGetter @Override public ImmutableMap getExtensions() { return extensions; } /** * @return The computed-at-construction value of the {@code referential} attribute */ @JsonProperty("referential") @JsonIgnore @Override public boolean isReferential() { InitShim shim = this.initShim; return shim != null ? shim.isReferential() : this.referential; } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractPathParameter#getRequired() required} attribute. * @param value The value for required, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final PathParameter withRequired(@Nullable Boolean value) { @Nullable Boolean newValue = value; if (Objects.equals(this.required, newValue)) return this; return validate(new PathParameter( newValue, this.style, this.explode, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractPathParameter#getRequired() required} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for required * @return A modified copy of {@code this} object */ public final PathParameter withRequired(Optional optional) { @Nullable Boolean value = optional.orElse(null); if (Objects.equals(this.required, value)) return this; return validate(new PathParameter( value, this.style, this.explode, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractPathParameter#getStyle() style} attribute. * @param value The value for style, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final PathParameter withStyle(@Nullable AbstractPathParameter.Style value) { @Nullable AbstractPathParameter.Style newValue = value; if (this.style == newValue) return this; return validate(new PathParameter( this.required, newValue, this.explode, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractPathParameter#getStyle() style} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for style * @return A modified copy of {@code this} object */ public final PathParameter withStyle(Optional optional) { @Nullable AbstractPathParameter.Style value = optional.orElse(null); if (Objects.equals(this.style, value)) return this; return validate(new PathParameter( this.required, value, this.explode, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractPathParameter#getExplode() explode} attribute. * @param value The value for explode, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final PathParameter withExplode(@Nullable Boolean value) { @Nullable Boolean newValue = value; if (Objects.equals(this.explode, newValue)) return this; return validate(new PathParameter( this.required, this.style, newValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractPathParameter#getExplode() explode} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for explode * @return A modified copy of {@code this} object */ public final PathParameter withExplode(Optional optional) { @Nullable Boolean value = optional.orElse(null); if (Objects.equals(this.explode, value)) return this; return validate(new PathParameter( this.required, this.style, value, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a value for the {@link AbstractPathParameter#getName() name} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for name * @return A modified copy of the {@code this} object */ public final PathParameter withName(String value) { if (this.name.equals(value)) return this; String newValue = Objects.requireNonNull(value, "name"); return validate(new PathParameter( this.required, this.style, this.explode, newValue, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a value for the {@link AbstractPathParameter#getSchema() schema} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for schema * @return A modified copy of the {@code this} object */ public final PathParameter withSchema(Referenceable value) { if (this.schema == value) return this; Referenceable newValue = Objects.requireNonNull(value, "schema"); return validate(new PathParameter( this.required, this.style, this.explode, this.name, newValue, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractPathParameter#getDefault() default} attribute. * @param value The value for getDefault, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final PathParameter withDefault(@Nullable Object value) { @Nullable Object newValue = value; if (this.getDefault == newValue) return this; return validate(new PathParameter( this.required, this.style, this.explode, this.name, this.schema, newValue, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractPathParameter#getDefault() default} attribute. * A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}. * @param optional A value for getDefault * @return A modified copy of {@code this} object */ public final PathParameter withDefault(Optional optional) { @Nullable Object value = optional.orElse(null); if (this.getDefault == value) return this; return validate(new PathParameter( this.required, this.style, this.explode, this.name, this.schema, value, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by replacing the {@link AbstractPathParameter#getExamples() examples} map with the specified map. * Nulls are not permitted as keys or values. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param entries The entries to be added to the examples map * @return A modified copy of {@code this} object */ public final PathParameter withExamples(Map entries) { if (this.examples == entries) return this; ImmutableMap newValue = ImmutableMap.copyOf(entries); return validate(new PathParameter( this.required, this.style, this.explode, this.name, this.schema, this.getDefault, newValue, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractPathParameter#getDeprecated() deprecated} attribute. * @param value The value for deprecated, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final PathParameter withDeprecated(@Nullable Boolean value) { @Nullable Boolean newValue = value; if (Objects.equals(this.deprecated, newValue)) return this; return validate(new PathParameter( this.required, this.style, this.explode, this.name, this.schema, this.getDefault, this.examples, newValue, this.description, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractPathParameter#getDeprecated() deprecated} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for deprecated * @return A modified copy of {@code this} object */ public final PathParameter withDeprecated(Optional optional) { @Nullable Boolean value = optional.orElse(null); if (Objects.equals(this.deprecated, value)) return this; return validate(new PathParameter( this.required, this.style, this.explode, this.name, this.schema, this.getDefault, this.examples, value, this.description, this.extensions)); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractPathParameter#getDescription() description} attribute. * @param value The value for description, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final PathParameter withDescription(@Nullable String value) { @Nullable String newValue = value; if (Objects.equals(this.description, newValue)) return this; return validate(new PathParameter( this.required, this.style, this.explode, this.name, this.schema, this.getDefault, this.examples, this.deprecated, newValue, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractPathParameter#getDescription() description} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for description * @return A modified copy of {@code this} object */ public final PathParameter withDescription(Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.description, value)) return this; return validate(new PathParameter( this.required, this.style, this.explode, this.name, this.schema, this.getDefault, this.examples, this.deprecated, value, this.extensions)); } /** * Copy the current immutable object by replacing the {@link AbstractPathParameter#getExtensions() extensions} map with the specified map. * Nulls are not permitted as keys or values. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param entries The entries to be added to the extensions map * @return A modified copy of {@code this} object */ public final PathParameter withExtensions(Map entries) { if (this.extensions == entries) return this; ImmutableMap newValue = ImmutableMap.copyOf(entries); return validate(new PathParameter( this.required, this.style, this.explode, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, newValue)); } /** * This instance is equal to all instances of {@code PathParameter} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof PathParameter && equalTo((PathParameter) another); } private boolean equalTo(PathParameter another) { return in.equals(another.in) && Objects.equals(required, another.required) && Objects.equals(style, another.style) && Objects.equals(explode, another.explode) && requiredOrDefault == another.requiredOrDefault && styleOrDefault.equals(another.styleOrDefault) && explodeOrDefault == another.explodeOrDefault && name.equals(another.name) && schema.equals(another.schema) && Objects.equals(getDefault, another.getDefault) && examples.equals(another.examples) && Objects.equals(deprecated, another.deprecated) && Objects.equals(description, another.description) && extensions.equals(another.extensions) && referential == another.referential; } /** * Computes a hash code from attributes: {@code in}, {@code required}, {@code style}, {@code explode}, {@code requiredOrDefault}, {@code styleOrDefault}, {@code explodeOrDefault}, {@code name}, {@code schema}, {@code getDefault}, {@code examples}, {@code deprecated}, {@code description}, {@code extensions}, {@code referential}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + in.hashCode(); h += (h << 5) + Objects.hashCode(required); h += (h << 5) + Objects.hashCode(style); h += (h << 5) + Objects.hashCode(explode); h += (h << 5) + Booleans.hashCode(requiredOrDefault); h += (h << 5) + styleOrDefault.hashCode(); h += (h << 5) + Booleans.hashCode(explodeOrDefault); h += (h << 5) + name.hashCode(); h += (h << 5) + schema.hashCode(); h += (h << 5) + Objects.hashCode(getDefault); h += (h << 5) + examples.hashCode(); h += (h << 5) + Objects.hashCode(deprecated); h += (h << 5) + Objects.hashCode(description); h += (h << 5) + extensions.hashCode(); h += (h << 5) + Booleans.hashCode(referential); return h; } /** * Prints the immutable value {@code PathParameter} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("PathParameter") .omitNullValues() .add("in", in) .add("required", required) .add("style", style) .add("explode", explode) .add("requiredOrDefault", requiredOrDefault) .add("styleOrDefault", styleOrDefault) .add("explodeOrDefault", explodeOrDefault) .add("name", name) .add("schema", schema) .add("default", getDefault) .add("examples", examples) .add("deprecated", deprecated) .add("description", description) .add("extensions", extensions) .add("referential", referential) .toString(); } /** * Utility type used to correctly read immutable object from JSON representation. * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonTypeInfo(use=JsonTypeInfo.Id.NONE) @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json extends AbstractPathParameter { @Nullable Optional required = Optional.empty(); @Nullable Optional style = Optional.empty(); @Nullable Optional explode = Optional.empty(); @Nullable String name; @Nullable Referenceable schema; @Nullable Optional getDefault = Optional.empty(); @Nullable Map examples = ImmutableMap.of(); @Nullable Optional deprecated = Optional.empty(); @Nullable Optional description = Optional.empty(); final Map extensions = new HashMap(); @JsonProperty("required") public void setRequired(Optional required) { this.required = required; } @JsonProperty("style") public void setStyle(Optional style) { this.style = style; } @JsonProperty("explode") public void setExplode(Optional explode) { this.explode = explode; } @JsonProperty("name") public void setName(String name) { this.name = name; } @JsonProperty("schema") public void setSchema(Referenceable schema) { this.schema = schema; } @JsonProperty("default") public void setDefault(Optional getDefault) { this.getDefault = getDefault; } @JsonProperty("examples") @JsonInclude(JsonInclude.Include.NON_EMPTY) public void setExamples(Map examples) { this.examples = examples; } @JsonProperty("deprecated") public void setDeprecated(Optional deprecated) { this.deprecated = deprecated; } @JsonProperty("description") public void setDescription(Optional description) { this.description = description; } @JsonAnySetter public void setExtensions(String key, Object value) { this.extensions.put(key, value); } @Override public Parameter.Location getIn() { throw new UnsupportedOperationException(); } @Override public Optional getRequired() { throw new UnsupportedOperationException(); } @Override public Optional getStyle() { throw new UnsupportedOperationException(); } @Override public Optional getExplode() { throw new UnsupportedOperationException(); } @Override public boolean getRequiredOrDefault() { throw new UnsupportedOperationException(); } @Override public AbstractPathParameter.Style getStyleOrDefault() { throw new UnsupportedOperationException(); } @Override public boolean getExplodeOrDefault() { throw new UnsupportedOperationException(); } @Override public String getName() { throw new UnsupportedOperationException(); } @Override public Referenceable getSchema() { throw new UnsupportedOperationException(); } @Override public Optional getDefault() { throw new UnsupportedOperationException(); } @Override public Map getExamples() { throw new UnsupportedOperationException(); } @Override public Optional getDeprecated() { throw new UnsupportedOperationException(); } @Override public Optional getDescription() { throw new UnsupportedOperationException(); } @Override public Map getExtensions() { throw new UnsupportedOperationException(); } @Override public boolean isReferential() { throw new UnsupportedOperationException(); } } /** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonCreator(mode = JsonCreator.Mode.DELEGATING) static PathParameter fromJson(Json json) { PathParameter.Builder builder = PathParameter.builder(); if (json.required != null) { builder.setRequired(json.required); } if (json.style != null) { builder.setStyle(json.style); } if (json.explode != null) { builder.setExplode(json.explode); } if (json.name != null) { builder.setName(json.name); } if (json.schema != null) { builder.setSchema(json.schema); } if (json.getDefault != null) { builder.setDefault(json.getDefault); } if (json.examples != null) { builder.putAllExamples(json.examples); } if (json.deprecated != null) { builder.setDeprecated(json.deprecated); } if (json.description != null) { builder.setDescription(json.description); } if (json.extensions != null) { builder.putAllExtensions(json.extensions); } return builder.build(); } private static PathParameter validate(PathParameter instance) { instance = (PathParameter) instance.normalizeExtensions(); return instance; } /** * Creates an immutable copy of a {@link AbstractPathParameter} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable PathParameter instance */ public static PathParameter copyOf(AbstractPathParameter instance) { if (instance instanceof PathParameter) { return (PathParameter) instance; } return PathParameter.builder() .from(instance) .build(); } /** * Creates a builder for {@link PathParameter PathParameter}. * @return A new PathParameter builder */ public static PathParameter.Builder builder() { return new PathParameter.Builder(); } /** * Builds instances of type {@link PathParameter PathParameter}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @NotThreadSafe public static final class Builder { private static final long INIT_BIT_NAME = 0x1L; private static final long INIT_BIT_SCHEMA = 0x2L; private long initBits = 0x3L; private @Nullable Boolean required; private @Nullable AbstractPathParameter.Style style; private @Nullable Boolean explode; private @Nullable String name; private @Nullable Referenceable schema; private @Nullable Object getDefault; private ImmutableMap.Builder examples = ImmutableMap.builder(); private @Nullable Boolean deprecated; private @Nullable String description; private ImmutableMap.Builder extensions = ImmutableMap.builder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.parameters.AbstractPathParameter} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(AbstractPathParameter instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.shared.WithMultipleExamples} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(WithMultipleExamples instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.shared.Deprecatable} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(Deprecatable instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.parameters.Parameter} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(Parameter instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.shared.Extensible} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(Extensible instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.shared.Describable} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(Describable instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { long bits = 0; if (object instanceof AbstractPathParameter) { AbstractPathParameter instance = (AbstractPathParameter) object; Optional explodeOptional = instance.getExplode(); if (explodeOptional.isPresent()) { setExplode(explodeOptional); } Optional styleOptional = instance.getStyle(); if (styleOptional.isPresent()) { setStyle(styleOptional); } if ((bits & 0x1L) == 0) { Optional requiredOptional = instance.getRequired(); if (requiredOptional.isPresent()) { setRequired(requiredOptional); } bits |= 0x1L; } } if (object instanceof WithMultipleExamples) { WithMultipleExamples instance = (WithMultipleExamples) object; putAllExamples(instance.getExamples()); } if (object instanceof Deprecatable) { Deprecatable instance = (Deprecatable) object; Optional deprecatedOptional = instance.getDeprecated(); if (deprecatedOptional.isPresent()) { setDeprecated(deprecatedOptional); } } if (object instanceof Parameter) { Parameter instance = (Parameter) object; setSchema(instance.getSchema()); setName(instance.getName()); Optional getDefaultOptional = instance.getDefault(); if (getDefaultOptional.isPresent()) { setDefault(getDefaultOptional); } if ((bits & 0x1L) == 0) { Optional requiredOptional = instance.getRequired(); if (requiredOptional.isPresent()) { setRequired(requiredOptional); } bits |= 0x1L; } } if (object instanceof Extensible) { Extensible instance = (Extensible) object; putAllExtensions(instance.getExtensions()); } if (object instanceof Describable) { Describable instance = (Describable) object; Optional descriptionOptional = instance.getDescription(); if (descriptionOptional.isPresent()) { setDescription(descriptionOptional); } } } /** * Initializes the optional value {@link AbstractPathParameter#getRequired() required} to required. * @param required The value for required, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setRequired(@Nullable Boolean required) { this.required = required; return this; } /** * Initializes the optional value {@link AbstractPathParameter#getRequired() required} to required. * @param required The value for required * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setRequired(Optional required) { this.required = required.orElse(null); return this; } /** * Initializes the optional value {@link AbstractPathParameter#getStyle() style} to style. * @param style The value for style, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setStyle(@Nullable AbstractPathParameter.Style style) { this.style = style; return this; } /** * Initializes the optional value {@link AbstractPathParameter#getStyle() style} to style. * @param style The value for style * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setStyle(Optional style) { this.style = style.orElse(null); return this; } /** * Initializes the optional value {@link AbstractPathParameter#getExplode() explode} to explode. * @param explode The value for explode, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setExplode(@Nullable Boolean explode) { this.explode = explode; return this; } /** * Initializes the optional value {@link AbstractPathParameter#getExplode() explode} to explode. * @param explode The value for explode * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setExplode(Optional explode) { this.explode = explode.orElse(null); return this; } /** * Initializes the value for the {@link AbstractPathParameter#getName() name} attribute. * @param name The value for name * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setName(String name) { this.name = Objects.requireNonNull(name, "name"); initBits &= ~INIT_BIT_NAME; return this; } /** * Initializes the value for the {@link AbstractPathParameter#getSchema() schema} attribute. * @param schema The value for schema * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setSchema(Referenceable schema) { this.schema = Objects.requireNonNull(schema, "schema"); initBits &= ~INIT_BIT_SCHEMA; return this; } /** * Initializes the optional value {@link AbstractPathParameter#getDefault() default} to getDefault. * @param getDefault The value for getDefault, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setDefault(@Nullable Object getDefault) { this.getDefault = getDefault; return this; } /** * Initializes the optional value {@link AbstractPathParameter#getDefault() default} to getDefault. * @param getDefault The value for getDefault * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setDefault(Optional getDefault) { this.getDefault = getDefault.orElse(null); return this; } /** * Put one entry to the {@link AbstractPathParameter#getExamples() examples} map. * @param key The key in the examples map * @param value The associated value in the examples map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putExamples(String key, Example value) { this.examples.put(key, value); return this; } /** * Put one entry to the {@link AbstractPathParameter#getExamples() examples} map. Nulls are not permitted * @param entry The key and value entry * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putExamples(Map.Entry entry) { this.examples.put(entry); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link AbstractPathParameter#getExamples() examples} map. Nulls are not permitted * @param examples The entries that will be added to the examples map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setExamples(Map examples) { this.examples = ImmutableMap.builder(); return putAllExamples(examples); } /** * Put all mappings from the specified map as entries to {@link AbstractPathParameter#getExamples() examples} map. Nulls are not permitted * @param examples The entries that will be added to the examples map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putAllExamples(Map examples) { this.examples.putAll(examples); return this; } /** * Initializes the optional value {@link AbstractPathParameter#getDeprecated() deprecated} to deprecated. * @param deprecated The value for deprecated, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setDeprecated(@Nullable Boolean deprecated) { this.deprecated = deprecated; return this; } /** * Initializes the optional value {@link AbstractPathParameter#getDeprecated() deprecated} to deprecated. * @param deprecated The value for deprecated * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setDeprecated(Optional deprecated) { this.deprecated = deprecated.orElse(null); return this; } /** * Initializes the optional value {@link AbstractPathParameter#getDescription() description} to description. * @param description The value for description, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setDescription(@Nullable String description) { this.description = description; return this; } /** * Initializes the optional value {@link AbstractPathParameter#getDescription() description} to description. * @param description The value for description * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setDescription(Optional description) { this.description = description.orElse(null); return this; } /** * Put one entry to the {@link AbstractPathParameter#getExtensions() extensions} map. * @param key The key in the extensions map * @param value The associated value in the extensions map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonAnySetter public final Builder putExtensions(String key, Object value) { this.extensions.put(key, value); return this; } /** * Put one entry to the {@link AbstractPathParameter#getExtensions() extensions} map. Nulls are not permitted * @param entry The key and value entry * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putExtensions(Map.Entry entry) { this.extensions.put(entry); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link AbstractPathParameter#getExtensions() extensions} map. Nulls are not permitted * @param extensions The entries that will be added to the extensions map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setExtensions(Map extensions) { this.extensions = ImmutableMap.builder(); return putAllExtensions(extensions); } /** * Put all mappings from the specified map as entries to {@link AbstractPathParameter#getExtensions() extensions} map. Nulls are not permitted * @param extensions The entries that will be added to the extensions map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putAllExtensions(Map extensions) { this.extensions.putAll(extensions); return this; } /** * Builds a new {@link PathParameter PathParameter}. * @return An immutable instance of PathParameter * @throws java.lang.IllegalStateException if any required attributes are missing */ public PathParameter build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return PathParameter.validate(new PathParameter( required, style, explode, name, schema, getDefault, examples.build(), deprecated, description, extensions.build())); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name"); if ((initBits & INIT_BIT_SCHEMA) != 0) attributes.add("schema"); return "Cannot build PathParameter, some of required attributes are not set " + attributes; } } }