@Test(description = "read composed schem refs #2616") public void readArrayComposedSchema_ticket2616() { Map<String, Schema> schemas = ModelConverters.getInstance().readAll(TestObject2616.class); Schema model = schemas.get("testObject"); Assert.assertNotNull(model); Map<String, Schema> properties = model.getProperties(); Assert.assertNotNull(properties.get("objects")); Assert.assertTrue(properties.get("objects") instanceof ArraySchema); model = schemas.get("AbstractObject"); Assert.assertNotNull(model); Assert.assertTrue(model instanceof ComposedSchema); Assert.assertTrue(((ComposedSchema)model).getOneOf().size() == 2); model = schemas.get("AObject"); Assert.assertNotNull(model); model = schemas.get("BObject"); Assert.assertNotNull(model); model = schemas.get("objects"); Assert.assertNull(model); }
@Test(description = "read single composed schem refs #2616") public void readComposedSchema_ticket2616() { Map<String, Schema> schemas = ModelConverters.getInstance().readAll(TestObject2616.TestObject2616_Schema.class); Schema model = schemas.get("TestObject2616_Schema"); Assert.assertNotNull(model); Map<String, Schema> properties = model.getProperties(); Assert.assertNotNull(properties.get("object")); Assert.assertTrue(properties.get("object").get$ref().equals("#/components/schemas/AbstractObject")); model = schemas.get("AbstractObject"); Assert.assertNotNull(model); Assert.assertTrue(model instanceof ComposedSchema); Assert.assertTrue(((ComposedSchema)model).getOneOf().size() == 2); model = schemas.get("AObject"); Assert.assertNotNull(model); model = schemas.get("BObject"); Assert.assertNotNull(model); model = schemas.get("objects"); Assert.assertNull(model); }
@Test(description = "read composed schem refs #2900") public void readComposedSchema_ticket2900() { Json.mapper().addMixIn(TestObjectTicket2900.GsonJsonPrimitive.class, TestObjectTicket2900.GsonJsonPrimitiveMixIn.class); Map<String, Schema> schemas = ModelConverters.getInstance().readAll(TestObjectTicket2900.class); Schema model = schemas.get("SomeDTO"); Assert.assertNotNull(model); Map<String, Schema> properties = model.getProperties(); Assert.assertNotNull(properties.get("value")); Assert.assertEquals(properties.get("value").get$ref(), "#/components/schemas/MyJsonPrimitive"); Assert.assertEquals(properties.get("valueWithMixIn").get$ref(), "#/components/schemas/GsonJsonPrimitive"); model = schemas.get("MyJsonPrimitive"); Assert.assertNotNull(model); Assert.assertTrue(((ComposedSchema)model).getOneOf().size() == 2); Assert.assertEquals(((ComposedSchema)model).getOneOf().get(0).getType(), "string"); Assert.assertEquals(((ComposedSchema)model).getOneOf().get(1).getType(), "number"); model = schemas.get("GsonJsonPrimitive"); Assert.assertNotNull(model); Assert.assertTrue(((ComposedSchema)model).getOneOf().size() == 2); Assert.assertEquals(((ComposedSchema)model).getOneOf().get(0).getType(), "string"); Assert.assertEquals(((ComposedSchema)model).getOneOf().get(1).getType(), "number"); Assert.assertNull(model.getProperties()); }
Assert.assertNull(properties.get("childName")); Assert.assertTrue(model instanceof ComposedSchema); Assert.assertTrue(((ComposedSchema)model).getOneOf().size() == 2); Assert.assertNull(properties.get("childName")); Assert.assertTrue(model instanceof ComposedSchema); Assert.assertTrue(((ComposedSchema)model).getOneOf().size() == 2);
private List<Schema> getInterfaces(ComposedSchema composed) { List<Schema> interfaces; if (composed.getAllOf() != null && !composed.getAllOf().isEmpty()) { return composed.getAllOf(); } else if (composed.getAnyOf() != null && !composed.getAnyOf().isEmpty()) { return composed.getAnyOf(); } else if (composed.getOneOf() != null && !composed.getOneOf().isEmpty()) { return composed.getOneOf(); } else { return null; } }
private List<Schema> getInterfaces(ComposedSchema composed) { if(composed.getAllOf() != null && composed.getAllOf().size() > 1) { return composed.getAllOf().subList(1, composed.getAllOf().size()); } else if(composed.getAnyOf() != null && !composed.getAnyOf().isEmpty()) { return composed.getAnyOf(); } else if(composed.getOneOf() != null && !composed.getOneOf().isEmpty()) { return composed.getOneOf(); } else { return null; } }
private List<Schema> getInterfaces(ComposedSchema composed) { if(composed.getAllOf() != null && composed.getAllOf().size() > 1) { return composed.getAllOf().subList(1, composed.getAllOf().size()); } else if(composed.getAnyOf() != null && !composed.getAnyOf().isEmpty()) { return composed.getAnyOf(); } else if(composed.getOneOf() != null && !composed.getOneOf().isEmpty()) { return composed.getOneOf(); } else { return null; } }
protected String schema(int deepness, ComposedSchema schema, DiffContext context) { StringBuilder sb = new StringBuilder(); if (schema.getAllOf() != null && schema.getAllOf() != null) { LOGGER.debug("All of schema"); schema .getAllOf() .stream() .map(this::resolve) .forEach(composedChild -> sb.append(schema(deepness, composedChild, context))); } if (schema.getOneOf() != null && schema.getOneOf() != null) { LOGGER.debug("One of schema"); sb.append(format("%sOne of:\n\n", indent(deepness))); schema .getOneOf() .stream() .map(this::resolve) .forEach(composedChild -> sb.append(schema(deepness + 1, composedChild, context))); } return sb.toString(); }
private Map<String, String> getMapping(ComposedSchema composedSchema) { Map<String, String> reverseMapping = new LinkedHashMap<>(); for (Schema schema : composedSchema.getOneOf()) { String ref = schema.get$ref(); if (ref == null) { throw new IllegalArgumentException("invalid oneOf schema"); } String schemaName = refPointer.getRefName(ref); if (schemaName == null) { throw new IllegalArgumentException("invalid schema: " + ref); } reverseMapping.put(ref, schemaName); } if (composedSchema.getDiscriminator().getMapping() != null) { for (String ref : composedSchema.getDiscriminator().getMapping().keySet()) { reverseMapping.put(composedSchema.getDiscriminator().getMapping().get(ref), ref); } } return reverseMapping .entrySet() .stream() .collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)); } }
ComposedSchema leftComposedSchema = (ComposedSchema) left; ComposedSchema rightComposedSchema = (ComposedSchema) right; if (CollectionUtils.isNotEmpty(leftComposedSchema.getOneOf()) || CollectionUtils.isNotEmpty(rightComposedSchema.getOneOf())) { "discriminator or property not found for oneOf schema"); } else if (!leftDis.getPropertyName().equals(rightDis.getPropertyName()) || (CollectionUtils.isEmpty(leftComposedSchema.getOneOf()) || CollectionUtils.isEmpty(rightComposedSchema.getOneOf()))) { changedSchema.setOldSchema(left); changedSchema.setNewSchema(right);
private void processProperty(Schema property, String file) { if (property != null) { if (StringUtils.isNotBlank(property.get$ref())) { processRefSchema(property, file); } if (property.getProperties() != null) { processProperties(property.getProperties(), file); } if (property instanceof ArraySchema) { processProperty(((ArraySchema) property).getItems(), file); } if (property.getAdditionalProperties() instanceof Schema) { processProperty(((Schema) property.getAdditionalProperties()), file); } if (property instanceof ComposedSchema) { ComposedSchema composed = (ComposedSchema) property; processProperties(composed.getAllOf(), file); processProperties(composed.getAnyOf(), file); processProperties(composed.getOneOf(), file); } } }
List<Schema> oneOf = ((ComposedSchema) schema).getOneOf(); if (oneOf != null) { for (Schema s : oneOf) {