001/* 002 * Copyright (C) 2016 Hobrasoft s.r.o. 003 * 004 * This program is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU Affero General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU Affero General Public License for more details. 013 * 014 * You should have received a copy of the GNU Affero General Public License 015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 016 */ 017package cz.hobrasoft.pdfmu.jackson; 018 019import com.fasterxml.jackson.databind.JsonMappingException; 020import com.fasterxml.jackson.databind.ObjectMapper; 021import com.fasterxml.jackson.databind.SerializationFeature; 022import com.fasterxml.jackson.module.jsonSchema.JsonSchema; 023import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper; 024import java.io.File; 025import java.io.IOException; 026import java.lang.reflect.Type; 027import java.util.HashMap; 028import java.util.Map; 029 030/** 031 * 032 * @author <a href="mailto:filip.bartek@hobrasoft.cz">Filip Bartek</a> 033 */ 034public class SchemaGenerator { 035 036 public static void main(String[] args) throws JsonMappingException, IOException { 037 ObjectMapper mapper = new ObjectMapper(); 038 mapper.enable(SerializationFeature.INDENT_OUTPUT); // nice formatting 039 040 SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); 041 042 Map<String, Type> types = new HashMap<>(); 043 types.put("RpcResponse", RpcResponse.class); 044 types.put("result/inspect", Inspect.class); 045 types.put("result/version set", VersionSet.class); 046 types.put("result/signature add", SignatureAdd.class); 047 types.put("result/empty", EmptyResult.class); 048 049 for (Map.Entry<String, Type> e : types.entrySet()) { 050 String name = e.getKey(); 051 String filename = String.format("schema/%s.json", name); 052 Type type = e.getValue(); 053 mapper.acceptJsonFormatVisitor(mapper.constructType(type), visitor); 054 JsonSchema jsonSchema = visitor.finalSchema(); 055 mapper.writeValue(new File(filename), jsonSchema); 056 } 057 } 058}