io.swagger.v3.oas.models.media.IntegerSchema Java Examples
The following examples show how to use
io.swagger.v3.oas.models.media.IntegerSchema.
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: ExampleBuilderTest.java From swagger-inflector with Apache License 2.0 | 6 votes |
@Test public void testRecursiveModel() throws Exception { Schema person = new Schema(); Schema property1 = new IntegerSchema().name("age").example(42); Schema property2 = new Schema().$ref("Person").name("spouse"); person.addProperties("age", property1); person.addProperties("spouse", property2); Map<String, Schema> definitions = new HashMap<>(); definitions.put("Person", person); Example rep = (Example) ExampleBuilder.fromSchema(new Schema().$ref("Person"), definitions); assertEqualsIgnoreLineEnding(Json.pretty(rep), "{\n \"age\" : 42\n}"); String xmlString = new XmlExampleSerializer().serialize(rep); assertEqualsIgnoreLineEnding(xmlString, "<?xml version='1.1' encoding='UTF-8'?><Person><age>42</age></Person>"); }
Example #2
Source File: OpenAPIResolverTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test(description = "resolve operation parameter remote refs") public void testOperationParameterRemoteRefs() { final OpenAPI swagger = new OpenAPI(); List<Parameter> parameters = new ArrayList<>(); parameters.add(new Parameter().$ref("#/components/parameters/SampleParameter")); swagger.path("/fun", new PathItem() .get(new Operation() .parameters(parameters))); swagger.components(new Components().addParameters("SampleParameter", new QueryParameter() .name("skip") .schema(new IntegerSchema()))); final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve(); final List<Parameter> params = swagger.getPaths().get("/fun").getGet().getParameters(); assertEquals(params.size(), 1); final Parameter param = params.get(0); assertEquals(param.getName(), "skip"); }
Example #3
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testCodegenPetstore() { OpenAPIV3Parser parser = new OpenAPIV3Parser(); final OpenAPI openAPI = parser.read("src/test/resources/petstore-codegen.yaml"); Schema enumModel = openAPI.getComponents().getSchemas().get("Enum_Test"); assertNotNull(enumModel); Schema enumProperty = (Schema)enumModel.getProperties().get("enum_integer"); assertNotNull(enumProperty); assertTrue(enumProperty instanceof IntegerSchema); IntegerSchema enumIntegerProperty = (IntegerSchema) enumProperty; List<Number> integers = enumIntegerProperty.getEnum(); assertEquals(integers.get(0), new Integer(1)); assertEquals(integers.get(1), new Integer(-1)); Operation getOrderOperation = openAPI.getPaths().get("/store/order/{orderId}").getGet(); assertNotNull(getOrderOperation); Parameter orderId = getOrderOperation.getParameters().get(0); assertTrue(orderId instanceof PathParameter); PathParameter orderIdPathParam = (PathParameter) orderId; assertNotNull(orderIdPathParam.getSchema().getMinimum()); BigDecimal minimum = orderIdPathParam.getSchema().getMinimum(); assertEquals(minimum.toString(), "1"); }
Example #4
Source File: ArraySerializableParamExtractionTest.java From swagger-inflector with Apache License 2.0 | 6 votes |
@Test public void testConvertIntegerArraySSVValue() throws Exception { List<String> values = Arrays.asList("1 2 3"); Parameter parameter = new QueryParameter() .style(Parameter.StyleEnum.SPACEDELIMITED) .explode(false)//("csv") .schema(new ArraySchema() .items(new IntegerSchema())); Object o = utils.cast(values, parameter, tf.constructArrayType(Integer.class), null); assertTrue(o instanceof List); @SuppressWarnings("unchecked") List<Integer> objs = (List<Integer>) o; assertTrue(objs.size() == 3); assertEquals(objs.get(0), new Integer(1)); assertEquals(objs.get(1), new Integer(2)); assertEquals(objs.get(2), new Integer(3)); }
Example #5
Source File: ExampleBuilderTest.java From swagger-inflector with Apache License 2.0 | 6 votes |
@Test public void testInvalidExample() throws Exception { testInvalidExample( new IntegerSchema(), "asd", ExampleBuilder.SAMPLE_INT_PROPERTY_VALUE, 123 ); testInvalidExample( new IntegerSchema().format("int64"), "asd", ExampleBuilder.SAMPLE_LONG_PROPERTY_VALUE, 123 ); testInvalidExample( new NumberSchema().format("float"), "asd", ExampleBuilder.SAMPLE_FLOAT_PROPERTY_VALUE, 2.1f ); testInvalidExample( new NumberSchema().format("double"), "asd", ExampleBuilder.SAMPLE_DOUBLE_PROPERTY_VALUE, 3.1f ); // base types that don't implement setting a sample value testInvalidExample( new NumberSchema(), "asd", ExampleBuilder.SAMPLE_DECIMAL_PROPERTY_VALUE ); testInvalidExample( new IntegerSchema(), "asd", ExampleBuilder.SAMPLE_BASE_INTEGER_PROPERTY_VALUE ); }
Example #6
Source File: ExampleBuilderTest.java From swagger-inflector with Apache License 2.0 | 6 votes |
@Test public void testIssue127() throws Exception { IntegerSchema integerProperty = new IntegerSchema(); integerProperty.setFormat(null); integerProperty.setExample(new Long(4321)); Schema model = new Schema(); model.addProperties("unboundedInteger",integerProperty); Map<String, Schema> definitions = new HashMap<>(); definitions.put("Address", model); Example rep = ExampleBuilder.fromSchema(new Schema().$ref("Address"), definitions); Json.prettyPrint(rep); assertEqualsIgnoreLineEnding(Json.pretty(rep), "{\n" + " \"unboundedInteger\" : 4321\n" + "}"); }
Example #7
Source File: ExampleBuilderTest.java From swagger-inflector with Apache License 2.0 | 6 votes |
@Test public void testIssue133() throws Exception { IntegerSchema integerSchema = new IntegerSchema(); integerSchema.setFormat("int64"); integerSchema.setExample(new Long(4321)); Schema model = new Schema(); model.addProperties("int64",integerSchema); Map<String, Schema> definitions = new HashMap<>(); definitions.put("Address", model); Example rep = ExampleBuilder.fromSchema(new Schema().$ref("Address"), definitions); assertEqualsIgnoreLineEnding(Json.pretty(rep), "{\n" + " \"int64\" : 4321\n" + "}"); }
Example #8
Source File: Swift4ModelEnumTest.java From openapi-generator with Apache License 2.0 | 6 votes |
@Test(description = "convert a java model with an integer enum and a default value") public void convertIntegerDefaultValueTest() { final IntegerSchema enumSchema = new IntegerSchema(); enumSchema.setEnum(Arrays.asList(1, 2, 3)); enumSchema.setDefault(2); final Schema model = new Schema().type("object").addProperties("name", enumSchema); final DefaultCodegen codegen = new Swift4Codegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", model); Assert.assertEquals(cm.vars.size(), 1); final CodegenProperty enumVar = cm.vars.get(0); Assert.assertEquals(enumVar.baseName, "name"); Assert.assertEquals(enumVar.dataType, "Int"); Assert.assertEquals(enumVar.datatypeWithEnum, "Name"); Assert.assertEquals(enumVar.name, "name"); Assert.assertEquals(enumVar.defaultValue, "._2"); Assert.assertEquals(enumVar.baseType, "Int"); Assert.assertTrue(enumVar.isEnum); }
Example #9
Source File: Swift5ModelEnumTest.java From openapi-generator with Apache License 2.0 | 6 votes |
@Test(description = "convert a java model with an integer enum and a default value") public void convertIntegerDefaultValueTest() { final IntegerSchema enumSchema = new IntegerSchema(); enumSchema.setEnum(Arrays.asList(1, 2, 3)); enumSchema.setDefault(2); final Schema model = new Schema().type("object").addProperties("name", enumSchema); final DefaultCodegen codegen = new Swift5ClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", model); Assert.assertEquals(cm.vars.size(), 1); final CodegenProperty enumVar = cm.vars.get(0); Assert.assertEquals(enumVar.baseName, "name"); Assert.assertEquals(enumVar.dataType, "Int"); Assert.assertEquals(enumVar.datatypeWithEnum, "Name"); Assert.assertEquals(enumVar.name, "name"); Assert.assertEquals(enumVar.defaultValue, "._2"); Assert.assertEquals(enumVar.baseType, "Int"); Assert.assertTrue(enumVar.isEnum); }
Example #10
Source File: PageNumber.java From crnk-framework with Apache License 2.0 | 5 votes |
public Parameter parameter() { return new Parameter().name("page[number]") .description("Page number") .in("query") .schema( new IntegerSchema() .format("int64") ._default(1)); }
Example #11
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testIssueIntegerDefault() { OpenAPIV3Parser parser = new OpenAPIV3Parser(); ParseOptions options = new ParseOptions(); options.setResolve(true); final OpenAPI openAPI = parser.readLocation("integerDefault.yaml", null, options).getOpenAPI(); Assert.assertNotNull(openAPI); Assert.assertFalse (((IntegerSchema) openAPI.getPaths().get("/fileUpload").getPost().getRequestBody().getContent().get("multipart/form-data").getSchema().getProperties().get("intMetadata")).getFormat() == "int32"); Assert.assertNull ( openAPI.getPaths().get("/mockResponses/primitiveDoubleResponse").getGet().getResponses().get("200").getContent().get("application/json").getSchema().getFormat()); Assert.assertNull ( openAPI.getPaths().get("/issue-125").getGet().getResponses().get("200").getContent().get("*/*").getSchema().getFormat()); Assert.assertNull (openAPI.getPaths().get("/primitiveBody/binary").getPost().getRequestBody().getContent().get("application/octet-stream").getSchema().getFormat()); }
Example #12
Source File: V2ConverterTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test(description = "OpenAPI v2 converter - proper IntegerSchema parsing") public void testIssue1032() throws Exception { final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1032_YAML); assertNotNull(oas); Parameter unixTimestampQueryParameter = oas.getComponents().getParameters().get(UNIX_TIMESTAMP_QUERY_PARAM); assertNotNull(unixTimestampQueryParameter); Schema s = unixTimestampQueryParameter.getSchema(); assertTrue((s instanceof IntegerSchema), "actual type: " + s); IntegerSchema integerSchema = (IntegerSchema) s; assertEquals(INTEGER_TYPE, integerSchema.getType()); assertEquals(INT64_FORMAT, integerSchema.getFormat()); }
Example #13
Source File: DartDioModelTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with list property") public void listPropertyTest() { final Schema model = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema()) .addProperties("urls", new ArraySchema() .items(new StringSchema())) .addRequiredItem("id"); final DefaultCodegen codegen = new DartDioClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", model); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "id"); Assert.assertEquals(property1.dataType, "int"); Assert.assertEquals(property1.name, "id"); Assert.assertEquals(property1.defaultValue, "null"); Assert.assertEquals(property1.baseType, "int"); Assert.assertTrue(property1.hasMore); Assert.assertTrue(property1.required); Assert.assertTrue(property1.isPrimitiveType); Assert.assertFalse(property1.isContainer); final CodegenProperty property2 = cm.vars.get(1); Assert.assertEquals(property2.baseName, "urls"); Assert.assertEquals(property2.dataType, "BuiltList<String>"); Assert.assertEquals(property2.name, "urls"); Assert.assertEquals(property2.baseType, "BuiltList"); Assert.assertFalse(property2.hasMore); Assert.assertEquals(property2.containerType, "array"); Assert.assertFalse(property2.required); Assert.assertTrue(property2.isPrimitiveType); Assert.assertTrue(property2.isContainer); }
Example #14
Source File: DefaultValidatorTest.java From swagger-inflector with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = ConversionException.class) public void testInvalidDatatype() throws Exception { Parameter parameter = new QueryParameter() .name("test") .required(true) .schema(new IntegerSchema()); converter.convertAndValidate(Arrays.asList("oops"), parameter, Integer.class, null); }
Example #15
Source File: ResponseModelTest.java From swagger-inflector with Apache License 2.0 | 5 votes |
@Test public void testConvertIntegerPropertyWithExample() throws Exception { Schema p = new IntegerSchema() .example(3); Object o = ExampleBuilder.fromSchema(p, null); assertNotNull(o); assertTrue(o instanceof IntegerExample); assertEquals(((IntegerExample) o).asInt(), new Integer(3)); }
Example #16
Source File: ResponseModelTest.java From swagger-inflector with Apache License 2.0 | 5 votes |
@Test public void testConvertIntegerProperty() throws Exception { IntegerSchema p = new IntegerSchema(); Object o = ExampleBuilder.fromSchema(p, null); assertNotNull(o); assertTrue(o instanceof IntegerExample); assertEquals(((IntegerExample) o).asInt(), new Integer(0)); }
Example #17
Source File: AbstractGoCodegenTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test public void getTypeDeclarationTest() { final AbstractGoCodegen codegen = new P_AbstractGoCodegen(); // Create an alias to an array schema Schema<?> nestedArraySchema = new ArraySchema().items(new IntegerSchema().format("int32")); codegen.setOpenAPI(new OpenAPI().components(new Components().addSchemas("NestedArray", nestedArraySchema))); // Create an array schema with item type set to the array alias Schema<?> schema = new ArraySchema().items(new Schema().$ref("#/components/schemas/NestedArray")); ModelUtils.setGenerateAliasAsModel(false); String defaultValue = codegen.getTypeDeclaration(schema); Assert.assertEquals(defaultValue, "[][]int32"); ModelUtils.setGenerateAliasAsModel(true); defaultValue = codegen.getTypeDeclaration(schema); Assert.assertEquals(defaultValue, "[]NestedArray"); // Create a map schema with additionalProperties type set to array alias schema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/NestedArray")); ModelUtils.setGenerateAliasAsModel(false); defaultValue = codegen.getTypeDeclaration(schema); Assert.assertEquals(defaultValue, "map[string][]int32"); ModelUtils.setGenerateAliasAsModel(true); defaultValue = codegen.getTypeDeclaration(schema); Assert.assertEquals(defaultValue, "map[string]NestedArray"); }
Example #18
Source File: DefaultGeneratorTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test public void testProcessPaths() throws Exception { OpenAPI openAPI = TestUtils.createOpenAPI(); openAPI.setPaths(new Paths()); openAPI.getPaths().addPathItem("/path1", new PathItem().get(new Operation().operationId("op1").responses(new ApiResponses().addApiResponse("201", new ApiResponse().description("OK"))))); openAPI.getPaths().addPathItem("/path2", new PathItem().get(new Operation().operationId("op2").addParametersItem(new QueryParameter().name("p1").schema(new StringSchema())).responses(new ApiResponses().addApiResponse("201", new ApiResponse().description("OK"))))); openAPI.getPaths().addPathItem("/path3", new PathItem().addParametersItem(new QueryParameter().name("p1").schema(new StringSchema())).get(new Operation().operationId("op3").addParametersItem(new QueryParameter().name("p2").schema(new IntegerSchema())).responses(new ApiResponses().addApiResponse("201", new ApiResponse().description("OK"))))); openAPI.getPaths().addPathItem("/path4", new PathItem().addParametersItem(new QueryParameter().name("p1").schema(new StringSchema())).get(new Operation().operationId("op4").responses(new ApiResponses().addApiResponse("201", new ApiResponse().description("OK"))))); ClientOptInput opts = new ClientOptInput(); opts.setOpenAPI(openAPI); opts.setConfig(new DefaultCodegen()); DefaultGenerator generator = new DefaultGenerator(); generator.opts(opts); Map<String, List<CodegenOperation>> result = generator.processPaths(openAPI.getPaths()); Assert.assertEquals(result.size(), 1); List<CodegenOperation> defaultList = result.get("Default"); Assert.assertEquals(defaultList.size(), 4); Assert.assertEquals(defaultList.get(0).path, "/path1"); Assert.assertEquals(defaultList.get(0).allParams.size(), 0); Assert.assertEquals(defaultList.get(1).path, "/path2"); Assert.assertEquals(defaultList.get(1).allParams.size(), 1); Assert.assertEquals(defaultList.get(2).path, "/path3"); Assert.assertEquals(defaultList.get(2).allParams.size(), 2); Assert.assertEquals(defaultList.get(3).path, "/path4"); Assert.assertEquals(defaultList.get(3).allParams.size(), 1); }
Example #19
Source File: StaticHtmlGeneratorTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test public void testAdditionalPropertiesFalse() { OpenAPI openAPI = TestUtils.createOpenAPI(); final StaticHtmlGenerator codegen = new StaticHtmlGenerator(); Schema schema = new ObjectSchema() .additionalProperties(false) .addProperties("id", new IntegerSchema()) .addProperties("name", new StringSchema()); codegen.setOpenAPI(openAPI); CodegenModel cm = codegen.fromModel("test", schema); Assert.assertNotNull(cm); }
Example #20
Source File: ExampleBuilderTest.java From swagger-inflector with Apache License 2.0 | 5 votes |
@Test public void testXmlLong() throws Exception { IntegerSchema sp = new IntegerSchema(); Example ex = ExampleBuilder.fromSchema(sp.format("int64"), null); String xmlString = new XmlExampleSerializer().serialize(ex); assertEqualsIgnoreLineEnding(xmlString, "<?xml version='1.1' encoding='UTF-8'?><long>0</long>"); }
Example #21
Source File: ExampleBuilderTest.java From swagger-inflector with Apache License 2.0 | 5 votes |
@Test public void testXmlInteger() throws Exception { IntegerSchema sp = new IntegerSchema(); Example ex = ExampleBuilder.fromSchema(sp, null); String xmlString = new XmlExampleSerializer().serialize(ex); assertEqualsIgnoreLineEnding(xmlString, "<?xml version='1.1' encoding='UTF-8'?><integer>0</integer>"); }
Example #22
Source File: ValueCoercionTest.java From swagger-inflector with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = ConversionException.class) public void testConvertInvalidIntegerValue() throws Exception { List<String> values = Arrays.asList("1abczdf"); Parameter parameter = new QueryParameter().schema(new IntegerSchema()); Object o = utils.cast(values, parameter, tf.constructType(Integer.class), null); assertNull(o); }
Example #23
Source File: ValueCoercionTest.java From swagger-inflector with Apache License 2.0 | 5 votes |
@Test public void testConvertIntegerValue() throws Exception { List<String> values = Arrays.asList("1"); Parameter parameter = new QueryParameter().schema(new IntegerSchema()); Object o = utils.cast(values, parameter, tf.constructType(Integer.class), null); assertTrue(o instanceof Integer); }
Example #24
Source File: DataGenerator.java From zap-extensions with Apache License 2.0 | 5 votes |
public boolean isSupported(Schema<?> schema) { return schema instanceof ArraySchema || schema instanceof BooleanSchema || schema instanceof FileSchema || schema instanceof IntegerSchema || schema instanceof MapSchema || schema instanceof NumberSchema || schema instanceof StringSchema; }
Example #25
Source File: OASUtilsTest.java From crnk-framework with Apache License 2.0 | 5 votes |
@Test public void testLong() { MetaPrimitiveType type = new MetaPrimitiveType(); type.setName("long"); Schema schema = OASUtils.transformMetaResourceField(type); Assert.assertTrue(schema instanceof IntegerSchema); Assert.assertEquals("int64", schema.getFormat()); }
Example #26
Source File: OASUtilsTest.java From crnk-framework with Apache License 2.0 | 5 votes |
@Test public void testShort() { MetaPrimitiveType type = new MetaPrimitiveType(); type.setName("short"); Schema schema = OASUtils.transformMetaResourceField(type); Assert.assertTrue(schema instanceof IntegerSchema); Assert.assertEquals("int32", schema.getFormat()); Assert.assertEquals(new BigDecimal(-32768), schema.getMinimum()); Assert.assertEquals(new BigDecimal(32767), schema.getMaximum()); }
Example #27
Source File: OASUtilsTest.java From crnk-framework with Apache License 2.0 | 5 votes |
@Test public void testInteger() { MetaPrimitiveType type = new MetaPrimitiveType(); type.setName("integer"); Schema schema = OASUtils.transformMetaResourceField(type); Assert.assertTrue(schema instanceof IntegerSchema); Assert.assertEquals("int32", schema.getFormat()); }
Example #28
Source File: PageLimit.java From crnk-framework with Apache License 2.0 | 5 votes |
public Parameter parameter() { return new Parameter().name("page[limit]") .description("Max number of items") .in("query") .schema( new IntegerSchema() .format("int64") ._default(100) // TODO: resolve from application.properties.crnk.default-page-limit=20 .maximum(BigDecimal.valueOf(1000))); // TODO: resolve from application.properties.crnk.max-page-limit=1000 }
Example #29
Source File: PageSize.java From crnk-framework with Apache License 2.0 | 5 votes |
public Parameter parameter() { return new Parameter().name("page[size]") .description("Page size") .in("query") .schema( new IntegerSchema() .format("int64") ._default(0)); // TODO: resolve from application.properties.crnk.default-page-limit=20 }
Example #30
Source File: PageOffset.java From crnk-framework with Apache License 2.0 | 5 votes |
public Parameter parameter() { return new Parameter().name("page[offset]") .description("Page offset") .in("query") .schema( new IntegerSchema() .format("int64") ._default(0)); }