@Test public void testJsonSchemaGeneratorInputOutput() throws IOException { Collection<GeneratedFile> files = new JsonSchemaGenerator.ClassBuilder(Stream.of(PersonInputOutputParams.class)).build().generate(); assertEquals(1, files.size()); GeneratedFile file = files.iterator().next(); assertEquals("InputOutput_test.json", file.relativePath()); assertSchema(file, SchemaVersion.DRAFT_7); }
public Collection<GeneratedFile> generate() throws IOException { SchemaGeneratorConfigBuilder builder = new SchemaGeneratorConfigBuilder(schemaVersion, OptionPreset.PLAIN_JSON); builder.forTypesInGeneral().withStringFormatResolver(target -> target.getSimpleTypeDescription().equals("Date") ? "date-time" : null); builder.forFields().withIgnoreCheck(JsonSchemaGenerator::isNotUserTaskParam).withCustomDefinitionProvider(this::getInputOutput); SchemaGenerator generator = new SchemaGenerator(builder.build()); ObjectWriter writer = new ObjectMapper().writer(); Collection<GeneratedFile> files = new ArrayList<>(); for (Map.Entry<String, List<Class<?>>> entry : map.entrySet()) { ObjectNode merged = null; for (Class<?> c : entry.getValue()) { ObjectNode read = generator.generateSchema(c); if (merged == null) { merged = read; } else { JsonUtils.merge(read, merged); } } try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { writer.writeValue(outputStream, merged); files.add(new GeneratedFile(Type.JSON_SCHEMA, JsonSchemaUtil.getFileName(entry.getKey()), outputStream.toByteArray())); } } return files; }
JsonSchemaGenerator { public Collection<GeneratedFile> generate() throws IOException { SchemaGeneratorConfigBuilder builder = new SchemaGeneratorConfigBuilder(schemaVersion, OptionPreset.PLAIN_JSON); builder.forTypesInGeneral().withStringFormatResolver(target -> target.getSimpleTypeDescription().equals("Date") ? "date-time" : null); builder.forFields().withIgnoreCheck(JsonSchemaGenerator::isNotUserTaskParam).withCustomDefinitionProvider(this::getInputOutput); SchemaGenerator generator = new SchemaGenerator(builder.build()); ObjectWriter writer = new ObjectMapper().writer(); Collection<GeneratedFile> files = new ArrayList<>(); for (Map.Entry<String, List<Class<?>>> entry : map.entrySet()) { ObjectNode merged = null; for (Class<?> c : entry.getValue()) { ObjectNode read = generator.generateSchema(c); if (merged == null) { merged = read; } else { JsonUtils.merge(read, merged); } } try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { writer.writeValue(outputStream, merged); files.add(new GeneratedFile(Type.JSON_SCHEMA, JsonSchemaUtil.getFileName(entry.getKey()), outputStream.toByteArray())); } } return files; } }
JsonSchemaGenerator { public Collection<GeneratedFile> generate() throws IOException { SchemaGeneratorConfigBuilder builder = new SchemaGeneratorConfigBuilder(schemaVersion, OptionPreset.PLAIN_JSON); builder.forTypesInGeneral().withStringFormatResolver(target -> target.getSimpleTypeDescription().equals("Date") ? "date-time" : null); builder.forFields().withIgnoreCheck(JsonSchemaGenerator::isNotUserTaskParam).withCustomDefinitionProvider(this::getInputOutput); SchemaGenerator generator = new SchemaGenerator(builder.build()); ObjectWriter writer = new ObjectMapper().writer(); Collection<GeneratedFile> files = new ArrayList<>(); for (Map.Entry<String, List<Class<?>>> entry : map.entrySet()) { ObjectNode merged = null; for (Class<?> c : entry.getValue()) { ObjectNode read = generator.generateSchema(c); if (merged == null) { merged = read; } else { JsonUtils.merge(read, merged); } } try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { writer.writeValue(outputStream, merged); files.add(new GeneratedFile(Type.JSON_SCHEMA, JsonSchemaUtil.getFileName(entry.getKey()), outputStream.toByteArray())); } } return files; } private  JsonSchemaGenerator(Map<String, List<Class<?>>> map, SchemaVersion schemaVersion); }
JsonSchemaGenerator { public Collection<GeneratedFile> generate() throws IOException { SchemaGeneratorConfigBuilder builder = new SchemaGeneratorConfigBuilder(schemaVersion, OptionPreset.PLAIN_JSON); builder.forTypesInGeneral().withStringFormatResolver(target -> target.getSimpleTypeDescription().equals("Date") ? "date-time" : null); builder.forFields().withIgnoreCheck(JsonSchemaGenerator::isNotUserTaskParam).withCustomDefinitionProvider(this::getInputOutput); SchemaGenerator generator = new SchemaGenerator(builder.build()); ObjectWriter writer = new ObjectMapper().writer(); Collection<GeneratedFile> files = new ArrayList<>(); for (Map.Entry<String, List<Class<?>>> entry : map.entrySet()) { ObjectNode merged = null; for (Class<?> c : entry.getValue()) { ObjectNode read = generator.generateSchema(c); if (merged == null) { merged = read; } else { JsonUtils.merge(read, merged); } } try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { writer.writeValue(outputStream, merged); files.add(new GeneratedFile(Type.JSON_SCHEMA, JsonSchemaUtil.getFileName(entry.getKey()), outputStream.toByteArray())); } } return files; } private  JsonSchemaGenerator(Map<String, List<Class<?>>> map, SchemaVersion schemaVersion); Collection<GeneratedFile> generate(); }
JsonSchemaGenerator { public Collection<GeneratedFile> generate() throws IOException { SchemaGeneratorConfigBuilder builder = new SchemaGeneratorConfigBuilder(schemaVersion, OptionPreset.PLAIN_JSON); builder.forTypesInGeneral().withStringFormatResolver(target -> target.getSimpleTypeDescription().equals("Date") ? "date-time" : null); builder.forFields().withIgnoreCheck(JsonSchemaGenerator::isNotUserTaskParam).withCustomDefinitionProvider(this::getInputOutput); SchemaGenerator generator = new SchemaGenerator(builder.build()); ObjectWriter writer = new ObjectMapper().writer(); Collection<GeneratedFile> files = new ArrayList<>(); for (Map.Entry<String, List<Class<?>>> entry : map.entrySet()) { ObjectNode merged = null; for (Class<?> c : entry.getValue()) { ObjectNode read = generator.generateSchema(c); if (merged == null) { merged = read; } else { JsonUtils.merge(read, merged); } } try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { writer.writeValue(outputStream, merged); files.add(new GeneratedFile(Type.JSON_SCHEMA, JsonSchemaUtil.getFileName(entry.getKey()), outputStream.toByteArray())); } } return files; } private  JsonSchemaGenerator(Map<String, List<Class<?>>> map, SchemaVersion schemaVersion); Collection<GeneratedFile> generate(); static final Logger logger; static final SchemaVersion DEFAULT_SCHEMA_VERSION; }