RESTBuilder { public void build() throws Exception { FreeMarkerTool freeMarkerTool = FreeMarkerTool.getInstance(); Map<String, Object> context = HashMapBuilder.<String, Object>put( "configYAML", _configYAML ).put( "freeMarkerTool", freeMarkerTool ).put( "stringUtil", StringUtil_IW.getInstance() ).put( "validator", Validator_IW.getInstance() ).build(); if (_configYAML.isGenerateREST()) { _createApplicationFile(context); } if (Validator.isNotNull(_configYAML.getClientDir())) { _createClientAggregationFile(context); _createClientBaseJSONParserFile(context); _createClientFacetFile(context); _createClientHttpInvokerFile(context); _createClientPageFile(context); _createClientPaginationFile(context); _createClientPermissionFile(context); _createClientProblemFile(context); _createClientUnsafeSupplierFile(context); } List<String> validationErrorMessages = new ArrayList<>(); File[] files = FileUtil.getFiles(_configDir, "rest-openapi", ".yaml"); for (File file : files) { try { _checkOpenAPIYAMLFile(freeMarkerTool, file); } catch (Exception exception) { throw new RuntimeException( StringBundler.concat( "Error in file \"", file.getName(), "\": ", exception.getMessage())); } String yamlString = FileUtil.read(file); if (!_validateOpenAPIYAML( file.getName(), yamlString, validationErrorMessages)) { continue; } OpenAPIYAML openAPIYAML = _loadOpenAPIYAML(yamlString); Map<String, Schema> allSchemas = OpenAPIUtil.getAllSchemas( openAPIYAML); context.put("allSchemas", allSchemas); String escapedVersion = OpenAPIUtil.escapeVersion(openAPIYAML); context.put("escapedVersion", escapedVersion); Map<String, Schema> globalEnumSchemas = OpenAPIUtil.getGlobalEnumSchemas(openAPIYAML); context.put("globalEnumSchemas", globalEnumSchemas); context.put("openAPIYAML", openAPIYAML); if (_configYAML.isGenerateGraphQL()) { _createGraphQLMutationFile(context, escapedVersion); _createGraphQLQueryFile(context, escapedVersion); _createGraphQLServletDataFile(context, escapedVersion); } context.put("schemaName", "openapi"); _createOpenAPIResourceFile(context, escapedVersion); _createPropertiesFile(context, escapedVersion, "openapi"); Map<String, Schema> schemas = freeMarkerTool.getSchemas( openAPIYAML); _createExternalSchemaFiles( schemas, context, escapedVersion, openAPIYAML); Set<Map.Entry<String, Schema>> set = new HashSet<>( allSchemas.entrySet()); for (Map.Entry<String, Schema> entry : set) { Schema schema = entry.getValue(); String schemaName = entry.getKey(); _putSchema(context, schema, schemaName, new HashSet<>()); _createDTOFile(context, escapedVersion, schemaName); if (Validator.isNotNull(_configYAML.getClientDir())) { _createClientDTOFile(context, escapedVersion, schemaName); _createClientSerDesFile( context, escapedVersion, schemaName); } } for (Map.Entry<String, Schema> entry : globalEnumSchemas.entrySet()) { _putSchema( context, entry.getValue(), entry.getKey(), new HashSet<>()); _createEnumFile(context, escapedVersion, entry.getKey()); if (Validator.isNotNull(_configYAML.getClientDir())) { _createClientEnumFile( context, escapedVersion, entry.getKey()); } } schemas = freeMarkerTool.getAllSchemas(openAPIYAML, schemas); for (Map.Entry<String, Schema> entry : schemas.entrySet()) { String schemaName = entry.getKey(); List<JavaMethodSignature> javaMethodSignatures = freeMarkerTool.getResourceJavaMethodSignatures( _configYAML, openAPIYAML, schemaName); if (javaMethodSignatures.isEmpty()) { continue; } Schema schema = entry.getValue(); _putSchema( context, schema, schemaName, _getRelatedSchemaNames(allSchemas, javaMethodSignatures)); _createBaseResourceImplFile( context, escapedVersion, schemaName); _createPropertiesFile( context, escapedVersion, String.valueOf(context.get("schemaPath"))); _createResourceFactoryImplFile( context, escapedVersion, schemaName); _createResourceFile(context, escapedVersion, schemaName); _createResourceImplFile(context, escapedVersion, schemaName); if (Validator.isNotNull(_configYAML.getClientDir())) { _createClientResourceFile( context, escapedVersion, schemaName); } if (Validator.isNotNull(_configYAML.getTestDir())) { _createBaseResourceTestCaseFile( context, escapedVersion, schemaName); _createResourceTestFile( context, escapedVersion, schemaName); } } } if (!validationErrorMessages.isEmpty()) { String validationErrorMessagesString = StringUtil.merge( validationErrorMessages, StringPool.NEW_LINE); throw new RuntimeException( "OpenAPI validation errors:\n" + validationErrorMessagesString); } FileUtil.deleteFiles(_configYAML.getApiDir(), _files); if (Validator.isNotNull(_configYAML.getClientDir())) { FileUtil.deleteFiles(_configYAML.getClientDir(), _files); } FileUtil.deleteFiles(_configYAML.getImplDir(), _files); FileUtil.deleteFiles( _configYAML.getImplDir() + "/../resources/OSGI-INF/", _files); if (Validator.isNotNull(_configYAML.getTestDir())) { FileUtil.deleteFiles(_configYAML.getTestDir(), _files); } } RESTBuilder(
			File copyrightFile, File configDir,
			Boolean forceClientVersionDescription);  RESTBuilder(RESTBuilderArgs restBuilderArgs); static void main(String[] args); void build();  }
@Test public void testCreateRESTBuilder() throws Exception { String dependenciesPath = _getDependenciesPath(); RESTBuilder restBuilder = new RESTBuilder( new File(dependenciesPath, "copyright.txt"), new File(dependenciesPath), null); restBuilder.build(); String filesPath = _getFilesPath(); File applicationFile = new File( filesPath + "/sample-impl/src/main/java/com/example/sample" + "/internal/jaxrs/application/SampleApplication.java"); Assert.assertTrue(applicationFile.exists()); _assertResourceFilesExist(filesPath, "Document"); _assertResourceFilesExist(filesPath, "Folder"); File sampleApiDir = new File(filesPath + "/sample-api"); FileUtils.deleteDirectory(sampleApiDir); Assert.assertFalse(sampleApiDir.exists()); File sampleImplDir = new File(filesPath + "/sample-impl"); FileUtils.deleteDirectory(sampleImplDir); Assert.assertFalse(sampleImplDir.exists()); }