use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.
the class MapPropertyDeserializerTest method testBooleanAdditionalPropertiesSerialization.
@Test(description = "it should serialize a boolean additionalProperties")
public void testBooleanAdditionalPropertiesSerialization() throws Exception {
Operation operation = Json.mapper().readValue(json, Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
Schema responseSchema = response.getContent().get("*/*").getSchema();
Schema schema = new ObjectSchema().additionalProperties(true);
assertEquals(normalizeLineEnds(Json.pretty(schema)), "{\n" + " \"type\" : \"object\",\n" + " \"additionalProperties\" : true\n" + "}");
schema = new ObjectSchema().additionalProperties(responseSchema);
assertEquals(normalizeLineEnds(Json.pretty(schema)), "{\n" + " \"type\" : \"object\",\n" + " \"additionalProperties\" : {\n" + " \"type\" : \"object\",\n" + " \"additionalProperties\" : {\n" + " \"type\" : \"integer\",\n" + " \"format\" : \"int32\"\n" + " },\n" + " \"x-foo\" : \"vendor x\"\n" + " }\n" + "}");
}
use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.
the class MapPropertyDeserializerTest method testIssue1261InlineSchemaExample.
@Test(description = "it should read an example within an inlined schema")
public void testIssue1261InlineSchemaExample() throws Exception {
Operation operation = Yaml.mapper().readValue(" responses:\n" + " \"200\":\n" + " content:\n" + " '*/*':\n" + " description: OK\n" + " schema:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int32\n" + " name:\n" + " type: string\n" + " required: [id, name]\n" + " example: ok", Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
Schema schema = response.getContent().get("*/*").getSchema();
Object example = schema.getExample();
assertNotNull(example);
assertTrue(example instanceof String);
assertEquals(example, "ok");
}
use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.
the class MapPropertyDeserializerTest method testMapDeserialization.
@Test(description = "it should deserialize a response per #1349")
public void testMapDeserialization() throws Exception {
Operation operation = Json.mapper().readValue(json, Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
Schema responseSchema = response.getContent().get("*/*").getSchema();
assertNotNull(responseSchema);
assertTrue(responseSchema instanceof MapSchema);
MapSchema mp = (MapSchema) responseSchema;
assertTrue(mp.getAdditionalProperties() instanceof IntegerSchema);
}
use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.
the class JsonDeserializationTest method testNullExampleDeserialization.
@Test
public void testNullExampleDeserialization() throws Exception {
String yamlNull = "openapi: 3.0.1\n" + "paths:\n" + " /:\n" + " get:\n" + " description: Operation Description\n" + " operationId: operationId\n" + "components:\n" + " schemas:\n" + " UserStatus:\n" + " type: string\n" + " example: null\n";
String yamlMissing = "openapi: 3.0.1\n" + "paths:\n" + " /:\n" + " get:\n" + " description: Operation Description\n" + " operationId: operationId\n" + "components:\n" + " schemas:\n" + " UserStatus:\n" + " type: string\n";
OpenAPI oas = Yaml.mapper().readValue(yamlNull, OpenAPI.class);
Yaml.prettyPrint(oas);
assertNull(oas.getComponents().getSchemas().get("UserStatus").getExample());
assertTrue(oas.getComponents().getSchemas().get("UserStatus").getExampleSetFlag());
oas = Yaml.mapper().readValue(yamlMissing, OpenAPI.class);
Yaml.prettyPrint(oas);
assertNull(oas.getComponents().getSchemas().get("UserStatus").getExample());
assertFalse(oas.getComponents().getSchemas().get("UserStatus").getExampleSetFlag());
Yaml.prettyPrint(oas);
}
use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.
the class JsonDeserializationTest method testNullEnumItem.
@Test(description = "Deserialize null enum item")
public void testNullEnumItem() throws Exception {
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /:\n" + " get:\n" + " tags:\n" + " - MyTag\n" + " summary: Operation Summary\n" + " description: Operation Description\n" + " operationId: operationId\n" + " parameters:\n" + " - name: subscriptionId\n" + " in: query\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + "components:\n" + " schemas:\n" + " UserStatus:\n" + " type: integer\n" + " description: some int values with null\n" + " format: int32\n" + " enum:\n" + " - 1\n" + " - 2\n" + " - null\n";
OpenAPI oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
assertEquals(oas.getComponents().getSchemas().get("UserStatus").getEnum(), Arrays.asList(1, 2, null));
yaml = "openapi: 3.0.1\n" + "paths:\n" + " /:\n" + " get:\n" + " tags:\n" + " - MyTag\n" + " summary: Operation Summary\n" + " description: Operation Description\n" + " operationId: operationId\n" + " parameters:\n" + " - name: subscriptionId\n" + " in: query\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + "components:\n" + " schemas:\n" + " UserStatus:\n" + " type: string\n" + " description: some int values with null\n" + " enum:\n" + " - 1\n" + " - 2\n" + " - null\n";
oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
assertEquals(oas.getComponents().getSchemas().get("UserStatus").getEnum(), Arrays.asList("1", "2", null));
}
Aggregations