Java Code Examples for io.swagger.v3.oas.models.media.Schema#setMinProperties()

The following examples show how to use io.swagger.v3.oas.models.media.Schema#setMinProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OASMergeUtil.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
public static Schema mergeSchema(Schema thisSchema, Schema thatSchema) {
  if (thatSchema == null) {
    return thisSchema;
  }
  // Overwriting `implementation` is explicitly disallowed
  // Overwriting `not` is explicitly disallowed
  // Overwriting `oneOf` is explicitly disallowed
  // Overwriting `anyOf` is explicitly disallowed
  // Overwriting `allOf` is explicitly disallowed
  // Overwriting `name` is explicitly disallowed
  if (thatSchema.getTitle() != null) {
    thisSchema.setTitle(thatSchema.getTitle());
  }
  // Overwriting `multipleOf` is explicitly disallowed
  if (thatSchema.getMaximum() != null) {
    thisSchema.setMaximum(thatSchema.getMaximum());
  }
  if (thatSchema.getExclusiveMaximum() != null) {
    thisSchema.setExclusiveMaximum(thatSchema.getExclusiveMaximum());
  }

  if (thatSchema.getMinimum() != null) {
    thisSchema.setMinimum(thatSchema.getMinimum());
  }
  if (thatSchema.getExclusiveMinimum() != null) {
    thisSchema.setExclusiveMinimum(thatSchema.getExclusiveMinimum());
  }
  if (thatSchema.getMaxLength() != null) {
    thisSchema.setMaxLength(thatSchema.getMaxLength());
  }
  if (thatSchema.getMinLength() != null) {
    thisSchema.setMinLength(thatSchema.getMinLength());
  }
  if (thatSchema.getPattern() != null) {
    thisSchema.setPattern(thatSchema.getPattern());
  }
  if (thatSchema.getMaxProperties() != null) {
    thisSchema.setMaxProperties(thatSchema.getMaxProperties());
  }
  if (thatSchema.getMinProperties() != null) {
    thisSchema.setMinProperties(thatSchema.getMinProperties());
  }
  // RequiredProperties
  if (thatSchema.getRequired() != null) {
    thisSchema.setRequired(thatSchema.getRequired());
  }
  // Overwriting `name` is explicitly disallowed
  if (thatSchema.getDescription() != null) {
    thisSchema.setDescription(thatSchema.getDescription());
  }
  if (thatSchema.getFormat() != null) {
    thisSchema.setFormat(thatSchema.getFormat());
  }
  // Overwriting `ref` is explicitly disallowed
  if (thatSchema.getNullable() != null) {
    thisSchema.setNullable(thatSchema.getNullable());
  }
  // Overwriting `AccessMode` is explicitly disallowed
  if (thatSchema.getExample() != null) {
    thisSchema.setExample(thatSchema.getExample());
  }
  if (thatSchema.getExternalDocs() != null) {
    thisSchema.setExternalDocs(thatSchema.getExternalDocs());
  }
  if (thatSchema.getDeprecated() != null) {
    thisSchema.setDeprecated(thatSchema.getDeprecated());
  }
  if (thatSchema.getType() != null) {
    thisSchema.setType(thatSchema.getType());
  }
  if (thatSchema.getEnum() != null) {
    thisSchema.setEnum(thatSchema.getEnum());
  }
  if (thatSchema.getDefault() != null) {
    thisSchema.setDefault(thatSchema.getDefault());
  }
  // Overwriting `discriminator` is explicitly disallowed
  // Overwriting `hidden` is explicitly disallowed
  // Overwriting `subTypes` is explicitly disallowed
  if (thatSchema.getExtensions() != null) {
    thisSchema.setExtensions(thatSchema.getExtensions());
  }
  return thisSchema;
}
 
Example 2
Source File: InputModeller.java    From tcases with MIT License 4 votes vote down vote up
/**
 * Returns the {@link IVarDef input variable} representing the values for an object instance.
 */
@SuppressWarnings("rawtypes")
private IVarDef objectValueVar( String instanceVarTag, Schema<?> instanceSchema, boolean instanceItem)
  {
  // Ensure schema defined for all required properties, using a default empty schema if necessary.
  Map<String,Schema> propertyDefs = Optional.ofNullable( instanceSchema.getProperties()).orElse( new LinkedHashMap<String,Schema>());
  Optional.ofNullable( instanceSchema.getRequired())
    .map( required -> required.stream().filter( property -> !propertyDefs.containsKey( property)).collect( toList()))
    .filter( undefined -> !undefined.isEmpty())
    .ifPresent( undefined -> {
      undefined.stream().forEach( required -> propertyDefs.put( required, emptySchema()));
      instanceSchema.setProperties( propertyDefs);
      });

  // Reconcile any "required" constraints for read/WriteOnly properties.
  instanceSchema.setRequired(
    Optional.ofNullable( instanceSchema.getRequired()).orElse( emptyList())
    .stream()
    .filter( property -> expectedInView( propertyDefs.get( property)))
    .collect( toList()));

  // Accumulate constraints on the number of properties expected.
  PropertyCountConstraints constraints = new PropertyCountConstraints();
  constraints.setRequiredCount( Optional.ofNullable( instanceSchema.getRequired()).orElse( emptyList()).size());
  constraints.setTotalCount( objectTotalProperties( instanceSchema));

  constraints.setHasAdditional(
    // additionalProperties keyword is not false...
    Optional.ofNullable( instanceSchema.getAdditionalProperties())
    .map( additional -> additional.getClass().equals( Boolean.class)? (Boolean) additional : true)
    .orElse( true)
    &&
    // maxProperties not already satisfied by required properties
    Optional.ofNullable( instanceSchema.getMaxProperties())
    .map( max -> max > constraints.getRequiredCount())
    .orElse( true));

  // Ensure min/max range is feasible
  instanceSchema.setMinProperties(
    Optional.ofNullable( instanceSchema.getMinProperties())
    .map( min -> Optional.ofNullable( instanceSchema.getMaxProperties()).map( max -> adjustedMinOf( "Properties", min, max)).orElse( min))
    .orElse( null));

  // Ensure minimum is a usable constraint
  instanceSchema.setMinProperties(
    Optional.ofNullable( instanceSchema.getMinProperties())
    .filter( min -> isUsablePropertyLimit( "minProperties", min, constraints))
    .orElse( null));

  // Ensure maximum is a usable constraint
  instanceSchema.setMaxProperties(
    Optional.ofNullable( instanceSchema.getMaxProperties())
    .filter( max -> isUsablePropertyMax( "maxProperties", max, constraints))
    .orElse( null));

  // Are additional properties are required to satisfy the minimum?
  Integer minProperties = instanceSchema.getMinProperties();
  constraints.setRequiresAdditional(
    Optional.ofNullable( minProperties)
    .map( min -> min > constraints.getTotalCount() && constraints.hasAdditional())
    .orElse( false));

  // Are all properties effectively required to satisfy the minimum?
  constraints.setAllRequired(
    Optional.ofNullable( minProperties)
    .map( min -> min == constraints.getTotalCount() && !constraints.hasAdditional())
    .orElse( false));

  return
    VarSetBuilder.with( "Value")
    .when( has( instanceValueProperty( instanceVarTag)))
    .members( iterableOf( objectPropertyCountVar( instanceVarTag, instanceSchema, constraints)))
    .members( objectPropertiesVar( instanceVarTag, instanceSchema, constraints))
    .build();
  }