private String schema(String s) { final String refSchema = raml.getConsolidatedSchemas().get(s); return refSchema == null ? s : refSchema; }
private void assureSchemaGenerated() throws IOException { for (final Map.Entry<String, String> nameAndSchema : ramlFile.getConsolidatedSchemas().entrySet()) { storeLocallySingleSchema(nameAndSchema); } }
private void assureSchemaLoaded() throws IOException { final List<String> allSchemas = new ArrayList<>(ramlFile.getConsolidatedSchemas().keySet()); initAll(allSchemas); }
/** * @return a {schema file, schema name} tuple. */ public Entry<File, String> getSchemaFile(final String schemaNameOrContent) throws IOException { if (raml.getConsolidatedSchemas().containsKey(schemaNameOrContent)) { // schemaNameOrContent is actually a global name return new SimpleEntry<File, String>(new File(globalSchemaStore, schemaNameOrContent), schemaNameOrContent); } else { // this is not a global reference but a local schema def - dump it to a temp file so // the type generators can pick it up final String schemaFileName = "schema" + schemaNameOrContent.hashCode(); final File schemaFile = new File(globalSchemaStore, schemaFileName); FileUtils.writeStringToFile(schemaFile, schemaNameOrContent); return new SimpleEntry<File, String>(schemaFile, null); } }
/** * <p>getSchemaFile.</p> * * @return a {schema file, schema name} tuple. * @param schemaNameOrContent a {@link java.lang.String} object. * @throws java.io.IOException if any. */ public Entry<File, String> getSchemaFile(final String schemaNameOrContent) throws IOException { if (raml.getConsolidatedSchemas().containsKey(schemaNameOrContent)) { // schemaNameOrContent is actually a global name return new SimpleEntry<File, String>(new File(globalSchemaStore, schemaNameOrContent), schemaNameOrContent); } else { // this is not a global reference but a local schema def - dump it to a temp file so // the type generators can pick it up final String schemaFileName = "schema" + schemaNameOrContent.hashCode(); final File schemaFile = new File(globalSchemaStore, schemaFileName); FileUtils.writeStringToFile(schemaFile, schemaNameOrContent); return new SimpleEntry<File, String>(schemaFile, null); } }
private void loadSchema(MimeType mime) { final String schema = mime.getSchema(); if (schema == null) { return; } final String refSchema = raml.getConsolidatedSchemas().get(schema); final String schemaToUse = refSchema == null ? schema : refSchema; final String type = mime.getType(); final int pos = type.indexOf(';'); final String simpleType = pos < 0 ? type : type.substring(0, pos); if (simpleType.equals("application/json") || simpleType.endsWith("+json")) { try { loadJsonSchema(loc, schemaToUse); } catch (IOException e) { throw new RuntimeException(e); } } }
for (final Entry<String, String> nameAndSchema : raml.getConsolidatedSchemas().entrySet())
public Context(final Configuration configuration, final Raml raml) throws IOException { Validate.notNull(configuration, "configuration can't be null"); Validate.notNull(raml, "raml can't be null"); this.configuration = configuration; this.raml = raml; codeModel = new JCodeModel(); resourcesMethods = new HashMap<String, Set<String>>(); // prime the HTTP method annotation cache httpMethodAnnotations = new HashMap<String, Object>(); for (final Class<? extends Annotation> clazz : JAXRS_HTTP_METHODS) { httpMethodAnnotations.put(clazz.getSimpleName(), clazz); } // write all global schemas to a temporary directory globalSchemaStore = Files.createTempDir(); for (final Entry<String, String> nameAndSchema : raml.getConsolidatedSchemas().entrySet()) { final File schemaFile = new File(globalSchemaStore, nameAndSchema.getKey()); FileUtils.writeStringToFile(schemaFile, nameAndSchema.getValue()); } // configure the JSON -> POJO generator final GenerationConfig jsonSchemaGenerationConfig = configuration.createJsonSchemaGenerationConfig(); schemaMapper = new SchemaMapper(new RuleFactory(jsonSchemaGenerationConfig, new AnnotatorFactory().getAnnotator(configuration.getJsonMapper()), new SchemaStore()), new SchemaGenerator()); }
public static Reader resolveSchema(Raml raml, String schema) { final String refSchema = raml.getConsolidatedSchemas().get(schema); return refSchema == null ? new NamedReader(schema, new Message("schema.inline").toString()) : new NamedReader(refSchema, new Message("schema", schema).toString()); }