use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readSchemaArray.
@Test(dataProvider = "data")
public void readSchemaArray(JsonNode rootNode) throws Exception {
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
final Paths paths = openAPI.getPaths();
Assert.assertNotNull(paths);
Assert.assertEquals(paths.size(), 19);
// parameters operation get
PathItem petByStatusEndpoint = paths.get("/pet/findByTags");
Assert.assertNotNull(petByStatusEndpoint.getGet());
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().size(), 1);
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters().get(0).getSchema());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getSchema().getType(), "array");
Assert.assertEquals(((ArraySchema) (petByStatusEndpoint.getGet().getParameters().get(0).getSchema())).getItems().getType(), "string");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getName(), "tags");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getExplode(), Boolean.TRUE);
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getStyle(), StyleEnum.FORM);
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testArraySchema.
@Test
public void testArraySchema() throws Exception {
String json = "{\n" + " \"properties\": {\n" + " \"data\": {\n" + " \"description\": \"the array type\",\n" + " \"type\": \"array\",\n" + " \"items\": {\n" + " \"properties\": {\n" + " \"name\": {\n" + " \"description\": \"the inner type\",\n" + " \"type\": \"string\",\n" + " \"minLength\": 1\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"required\": [\n" + " \"data\"\n" + " ]\n" + "}";
Schema m = Json.mapper().readValue(json, Schema.class);
Schema data = (Schema) m.getProperties().get("data");
assertTrue(data instanceof ArraySchema);
ArraySchema ap = (ArraySchema) data;
assertEquals("the array type", ap.getDescription());
Schema inner = ap.getItems();
assertNotNull(inner);
assertTrue(inner instanceof ObjectSchema);
ObjectSchema op = (ObjectSchema) inner;
Schema name = op.getProperties().get("name");
assertEquals(name.getDescription(), "the inner type");
assertTrue((name).getMinLength() == 1);
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssueRelativeRefs2.
@Test
public void testIssueRelativeRefs2() {
String location = "exampleSpecs/specs/my-domain/test-api/v1/test-api-swagger_v1.json";
ParseOptions po = new ParseOptions();
po.setResolve(true);
SwaggerParseResult result = new OpenAPIParser().readLocation(location, null, po);
assertNotNull(result.getOpenAPI());
OpenAPI openAPI = result.getOpenAPI();
Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
Assert.assertTrue(schemas.get("confirmMessageType_v01").getProperties().get("resources") instanceof ArraySchema);
ArraySchema arraySchema = (ArraySchema) schemas.get("confirmMessageType_v01").getProperties().get("resources");
Schema prop = (Schema) arraySchema.getItems().getProperties().get("resourceID");
assertEquals(prop.get$ref(), "#/components/schemas/simpleIDType_v01");
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssueRelativeRefs1.
@Test
public void testIssueRelativeRefs1() {
String location = "specs2/my-domain/test-api/v1/test-api-swagger_v1.json";
ParseOptions po = new ParseOptions();
po.setResolve(true);
SwaggerParseResult result = new OpenAPIParser().readLocation(location, null, po);
assertNotNull(result.getOpenAPI());
OpenAPI openAPI = result.getOpenAPI();
Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
Assert.assertTrue(schemas.get("test-api-schema_v01").getProperties().get("testingApi") instanceof ArraySchema);
ArraySchema arraySchema = (ArraySchema) schemas.get("test-api-schema_v01").getProperties().get("testingApi");
Schema prop = (Schema) arraySchema.getItems().getProperties().get("itemID");
assertEquals(prop.get$ref(), "#/components/schemas/simpleIDType_v01");
}
use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.
the class SwaggerConverter method convert.
public Schema convert(io.swagger.models.Model v2Model) {
if (v2Model == null) {
return null;
}
Schema result;
if (v2Model instanceof ArrayModel) {
ArraySchema arraySchema = Json.mapper().convertValue(v2Model, ArraySchema.class);
arraySchema.setItems(convert(((ArrayModel) v2Model).getItems()));
result = arraySchema;
} else if (v2Model instanceof ComposedModel) {
ComposedModel composedModel = (ComposedModel) v2Model;
ComposedSchema composed = new ComposedSchema();
composed.setDescription(composedModel.getDescription());
if (composedModel.getExample() != null) {
composed.setExample(composedModel.getExample());
}
if (composedModel.getExternalDocs() != null) {
composed.setExternalDocs(convert(composedModel.getExternalDocs()));
}
composed.setTitle(composedModel.getTitle());
composed.setExtensions(convert(composedModel.getVendorExtensions()));
composed.setAllOf(composedModel.getAllOf().stream().map(this::convert).collect(Collectors.toList()));
addProperties(v2Model, composed);
result = composed;
} else {
String v2discriminator = null;
if (v2Model instanceof ModelImpl) {
ModelImpl model = (ModelImpl) v2Model;
v2discriminator = model.getDiscriminator();
model.setDiscriminator(null);
}
result = Json.mapper().convertValue(v2Model, Schema.class);
addProperties(v2Model, result);
if (v2Model instanceof ModelImpl) {
ModelImpl model = (ModelImpl) v2Model;
if (model.getAdditionalProperties() != null) {
result.setAdditionalProperties(convert(model.getAdditionalProperties()));
}
} else if (v2Model instanceof RefModel) {
RefModel ref = (RefModel) v2Model;
if (ref.get$ref().indexOf("#/definitions") == 0) {
String updatedRef = "#/components/schemas" + ref.get$ref().substring("#/definitions".length());
result.set$ref(updatedRef);
}
}
if (v2discriminator != null) {
Discriminator discriminator = new Discriminator();
discriminator.setPropertyName(v2discriminator);
result.setDiscriminator(discriminator);
}
}
if (v2Model.getVendorExtensions() != null) {
Object nullableExtension = v2Model.getVendorExtensions().get("x-nullable");
if (nullableExtension != null) {
result.setNullable((Boolean) nullableExtension);
}
}
return result;
}
Aggregations