Java Code Examples for io.swagger.v3.oas.models.media.Schema#getMinProperties()
The following examples show how to use
io.swagger.v3.oas.models.media.Schema#getMinProperties() .
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: SchemaMinPropertiesChangeInRequestValidator.java From servicecomb-toolkit with Apache License 2.0 | 4 votes |
@Override protected Integer getProperty(Schema schema) { return schema.getMinProperties(); }
Example 2
Source File: SchemaMinPropertiesChangeInResponseValidator.java From servicecomb-toolkit with Apache License 2.0 | 4 votes |
@Override protected Integer getProperty(Schema schema) { return schema.getMinProperties(); }
Example 3
Source File: OASMergeUtil.java From crnk-framework with Apache License 2.0 | 4 votes |
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 4
Source File: InputModeller.java From tcases with MIT License | 4 votes |
/** * 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(); }
Example 5
Source File: InputModeller.java From tcases with MIT License | 4 votes |
/** * Returns the {@link IVarDef input variable} representing the number of properties for an object instance. */ private Optional<IVarDef> objectPropertyCountVar( String instanceVarTag, Schema<?> instanceSchema, PropertyCountConstraints constraints) { // Accumulate property count values depending on constraints ListBuilder<VarValueDef> countValues = ListBuilder.to(); // Property count has usable constraints? Integer minProperties = instanceSchema.getMinProperties(); Integer maxProperties = instanceSchema.getMaxProperties(); if( !(minProperties == null && maxProperties == null)) { // Yes, upper bound defined? if( maxProperties != null) { // Yes, with provision for any lower bound... if( minProperties != null) { belowMinPropertiesFailure( instanceVarTag, minProperties, constraints) .ifPresent( failure -> countValues.add( failure)); } else if( constraints.getRequiredCount() == 0) { countValues.add( VarValueDefBuilder.with( 0) .when( not( objectPropertiesProperty( instanceVarTag))) .type( VarValueDef.Type.ONCE) .build()); } // ... and keeping in mind that maxProperties can exceed total count when additional properties are allowed... Optional<Integer> maxDefined = Optional.ofNullable( maxProperties > constraints.getTotalCount() ? constraints.getTotalCount() + 1 : null); // ...define coverage w.r.t. upper bound countValues .add( VarValueDefBuilder.with( String.format( "%s%s", maxProperties.equals( minProperties)? "" : "<= ", maxProperties)) .when( notMoreThan( objectPropertiesProperty( instanceVarTag), maxDefined.orElse( maxProperties))) .build()) .add( VarValueDefBuilder.with( String.format( "> %s", maxProperties)) .when( moreThan( objectPropertiesProperty( instanceVarTag), maxDefined.map( md -> md - 1).orElse( maxProperties))) .type( VarValueDef.Type.FAILURE) .build()); } else { // No, define coverage w.r.t. lower bound ICondition minSatisfied = // All properties effectively required? If so, satisfaction of minProperties is the only successful outcome. constraints.allRequired() ? null : notLessThan( objectPropertiesProperty( instanceVarTag), Math.min( minProperties, constraints.getTotalCount())); countValues .add( VarValueDefBuilder.with( String.format( ">= %s", minProperties)) .when( minSatisfied) .build()); belowMinPropertiesFailure( instanceVarTag, minProperties, constraints) .ifPresent( failure -> countValues.add( failure)); } } // No, but are all properties optional? else if( constraints.getRequiredCount() == 0 && constraints.getTotalCount() > 0) { // Yes, ensure coverage of "no properties" case. countValues .add( VarValueDefBuilder.with( 0) .when( not( objectPropertiesProperty( instanceVarTag))) .type( VarValueDef.Type.ONCE) .build()) .add( VarValueDefBuilder.with( "> 0") .when( has( objectPropertiesProperty( instanceVarTag))) .type( VarValueDef.Type.VALID) .build()); } return Optional.of( countValues.build()) .filter( values -> !values.isEmpty()) .map( values -> VarDefBuilder.with( "Property-Count") .values( values) .build()); }