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

The following examples show how to use io.swagger.v3.oas.models.media.Schema#setEnum() . 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: StringTypeValidatorTest.java    From swagger-inflector with Apache License 2.0 6 votes vote down vote up
@Test
public void testLocalDateConversionEnum() throws Exception {
    List<String> values = new ArrayList<String>();
    for(int i = 1; i <= 3; i++) {
        String str = "2015-01-0" + i;
        values.add(str);
    }

    QueryParameter parameter = new QueryParameter();
        parameter.setName("test");
        Schema schema = new DateSchema();
        schema.setEnum(values);
        parameter.setSchema(schema);

    converter.validate(new LocalDate("2015-01-02"), parameter);
}
 
Example 2
Source File: StringTypeValidatorTest.java    From swagger-inflector with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = ValidationException.class)
public void testInvalidLocalDateConversionEnum() throws Exception {
    List<String> values = new ArrayList<String>();
    for(int i = 1; i <= 3; i++) {
        String str = "2015-01-0" + i;
        values.add(str);
    }

    QueryParameter parameter = new QueryParameter();
    parameter.setName("test");
    Schema schema = new DateSchema();
    schema.setEnum(values);

    parameter.setSchema(schema);

    converter.validate(new LocalDate("2015-01-04"), parameter);
}
 
Example 3
Source File: OpenAPIDeserializerTest.java    From swagger-parser with Apache License 2.0 6 votes vote down vote up
@Test
public void testIssue360() {
    OpenAPI openAPI = new OpenAPI();

    Schema model = new Schema();
    model.setEnum((List<String>) null);
    openAPI.components(new Components().addSchemas("modelWithNullEnum", model));

    String json = Json.pretty(openAPI);

    OpenAPIV3Parser parser = new OpenAPIV3Parser();

    SwaggerParseResult result = parser.readContents(json, null, null);
    OpenAPI rebuilt = result.getOpenAPI();
    assertNotNull(rebuilt);
}
 
Example 4
Source File: RefHelper.java    From raptor with Apache License 2.0 5 votes vote down vote up
private Schema buildSchema(ProtoType protoType) {
    Schema schema = new Schema();
    Type type = this.schema.getType(protoType);
    if (type instanceof EnumType) {
        schema.type("integer");
        // TODO: 2018/5/22 追加特别的描述
        schema.description(getDescriptionFromEnumType((EnumType) type));
        schema.setEnum(((EnumType) type).constants().stream().map(EnumConstant::tag).collect(Collectors.toList()));
    } else if (type instanceof MessageType) {
        schema.properties(buildProperties((MessageType) type));
    }
    return schema;
}
 
Example 5
Source File: KindModelResolver.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
protected void _addEnumProps(final Class<?> propClass, @SuppressWarnings("rawtypes") final Schema property) {
    if (Kind.class.equals(propClass)) {
        @SuppressWarnings("unchecked")
        final Schema<String> kindProperty = property;
        kindProperty.setEnum(KINDS);
    } else {
        super._addEnumProps(propClass, property);
    }
}
 
Example 6
Source File: NumericValidatorTest.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidIntegerEnum() throws Exception {
    QueryParameter parameter = new QueryParameter();
    parameter.setName("test");
    Schema schema = new Schema();
    schema.setEnum(Arrays.asList("1", "2", "3"));
    parameter.setSchema(schema);

    InputConverter.getInstance().validate(new Integer(3), parameter);
}
 
Example 7
Source File: NumericValidatorTest.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = ValidationException.class)
public void testInvalidIntegerEnum() throws Exception {
    QueryParameter parameter = new QueryParameter();
    parameter.setName("test");
    Schema schema = new Schema();
    schema.setEnum(Arrays.asList("1", "2", "3"));
    parameter.setSchema(schema);

    InputConverter.getInstance().validate(new Integer(4), parameter);
}
 
Example 8
Source File: NumericValidatorTest.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidLongEnum() throws Exception {
    QueryParameter parameter = new QueryParameter();
    parameter.setName("test");
    Schema schema = new NumberSchema();
    schema.setEnum(Arrays.asList("1", "2", "3"));
    parameter.setSchema(schema);

    InputConverter.getInstance().validate(new Long(3), parameter);
}
 
Example 9
Source File: NumericValidatorTest.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = ValidationException.class)
public void testInvalidLongEnum() throws Exception {
    QueryParameter parameter = new QueryParameter();
    parameter.setName("test");
    Schema schema = new NumberSchema();
    schema.setEnum(Arrays.asList("1", "2", "3"));
    parameter.setSchema(schema);

    InputConverter.getInstance().validate(new Long(4), parameter);
}
 
Example 10
Source File: NumericValidatorTest.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidDoubleEnum() throws Exception {
    QueryParameter parameter = new QueryParameter();
    parameter.setName("test");
    Schema schema = new NumberSchema();
    schema.setEnum(Arrays.asList(
            new Double(1).toString(),
            new Double(2).toString(),
            new Double(3).toString()));
    parameter.setSchema(schema);

    InputConverter.getInstance().validate(new Double(3), parameter);
}
 
Example 11
Source File: NumericValidatorTest.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = ValidationException.class)
public void testInvalidDoubleEnum() throws Exception {
    QueryParameter parameter = new QueryParameter();
    parameter.setName("test");
    Schema schema = new NumberSchema();
    schema.setEnum(Arrays.asList(
            new Double(1).toString(),
            new Double(2).toString(),
            new Double(3).toString()));
    parameter.setSchema(schema);

    InputConverter.getInstance().validate(new Double(4), parameter);
}
 
Example 12
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;
}