test_class.declarator: RES_DIR = OpenAPICommandTest.getResourceFolderPath()
test_class.modifier: private static final
test_class.original_string: private static final Path RES_DIR = OpenAPICommandTest.getResourceFolderPath();
test_class.type: Path
test_class.var_name: RES_DIR
test_class.declarator: petProject
test_class.modifier: private
test_class.original_string: private OpenAPIBallerinaProject petProject;
test_class.type: OpenAPIBallerinaProject
test_class.var_name: petProject
test_class.file: misc/openapi-ballerina/modules/openapi-to-ballerina-generator/src/test/java/org/ballerinalang/openapi/cmd/OpenApiGenServiceCmdTest.java
test_class.identifier: OpenApiGenServiceCmdTest
test_class.superclass: extends OpenAPICommandTest
test_case.body: @Test(description = "Test open-api genservice for successful service generation with all of schema type",
              enabled = false)
      public void testAllOfSchemaGen() throws IOException {
          Path allOfYaml = RES_DIR.resolve(Paths.get("allof-petstore.yaml"));
          createBalProjectModule(petProject, "allofmodule");
          String[] args = {"allofmodule:allofservice", allOfYaml.toString()};
  
          OpenApiGenServiceCmd cmd = new OpenApiGenServiceCmd(printStream, petProject.getBalProjectPath().toString());
          new CommandLine(cmd).parseArgs(args);
  
          String output = "";
          try {
              cmd.execute();
          } catch (BLauncherException e) {
              output = e.getDetailedMessages().get(0);
          }
  
          Path expectedServiceFile = RES_DIR.resolve(Paths.get("expected_gen",
                  "allOf-schema-petstore.bal"));
  
          Stream<String> expectedServiceLines = Files.lines(expectedServiceFile);
          String expectedSchema = expectedServiceLines.collect(Collectors.joining("\n"));
  
          if (Files.exists(petProject.getResourcePath().resolve(allOfYaml.getFileName()))
                  && Files.exists(petProject.getSrcPath().resolve("allofmodule").resolve("allofservice.bal"))) {
  
              Stream<String> serviceLines = Files.lines(petProject.getSrcPath()
                      .resolve("allofmodule").resolve("schema.bal"));
              String generatedSchema = serviceLines.collect(Collectors.joining("\n"));
              serviceLines.close();
  
              Pattern pattern = Pattern.compile("\\bcontract\\b: \"(.*?)\"");
              Matcher matcher = pattern.matcher(generatedSchema);
              matcher.find();
  
              if (expectedSchema.trim().equals(generatedSchema.trim())) {
                  Assert.assertTrue(true);
              } else {
                  Assert.fail("Expected content and actual generated content is mismatched for: "
                          + allOfYaml.toString());
              }
  
          } else {
              Assert.fail("Service generation for All Of Schema type failed.");
          }
      }
test_case.class_method_signature: OpenApiGenServiceCmdTest.testAllOfSchemaGen()
test_case.full_signature: @Test(description = "Test open-api genservice for successful service generation with all of schema type", enabled = false) public void testAllOfSchemaGen()
test_case.identifier: testAllOfSchemaGen
test_case.invocations: resolve get createBalProjectModule toString toString getBalProjectPath parseArgs execute get getDetailedMessages resolve get lines collect joining exists resolve getResourcePath getFileName exists resolve resolve getSrcPath lines resolve resolve getSrcPath collect joining close compile matcher find equals trim trim assertTrue fail toString fail
test_case.modifiers: @Test(description = "Test open-api genservice for successful service generation with all of schema type", enabled = false) public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testAllOfSchemaGen()
focal_class.declarator: CMD_NAME = "openapi-gen-service"
focal_class.modifier: private static final
focal_class.original_string: private static final String CMD_NAME = "openapi-gen-service";
focal_class.type: String
focal_class.var_name: CMD_NAME
focal_class.declarator: outStream
focal_class.modifier: private
focal_class.original_string: private PrintStream outStream;
focal_class.type: PrintStream
focal_class.var_name: outStream
focal_class.declarator: executionPath
focal_class.modifier: private
focal_class.original_string: private String executionPath;
focal_class.type: String
focal_class.var_name: executionPath
focal_class.declarator: moduleArgs
focal_class.modifier: @CommandLine.Parameters(index = "0", split = ":")
      private
focal_class.original_string: @CommandLine.Parameters(index = "0", split = ":")
      private List<String> moduleArgs;
focal_class.type: List<String>
focal_class.var_name: moduleArgs
focal_class.declarator: argList
focal_class.modifier: @CommandLine.Parameters(index = "1..*")
      private
focal_class.original_string: @CommandLine.Parameters(index = "1..*")
      private List<String> argList;
focal_class.type: List<String>
focal_class.var_name: argList
focal_class.declarator: skipBind = false
focal_class.modifier: @CommandLine.Option(names = {"-s", "--skip-bind"}, description = "Skip copying of the used contract to project")
focal_class.original_string: @CommandLine.Option(names = {"-s", "--skip-bind"}, description = "Skip copying of the used contract to project")
      boolean skipBind = false;
focal_class.type: boolean
focal_class.var_name: skipBind
focal_class.declarator: output = ""
focal_class.modifier: @CommandLine.Option(names = {"-o", "--output"}, description = "where to write the generated " +
              "files (current dir by default)")
      private
focal_class.original_string: @CommandLine.Option(names = {"-o", "--output"}, description = "where to write the generated " +
              "files (current dir by default)")
      private String output = "";
focal_class.type: String
focal_class.var_name: output
focal_class.declarator: helpFlag
focal_class.modifier: @CommandLine.Option(names = {"-h", "--help"}, hidden = true)
      private
focal_class.original_string: @CommandLine.Option(names = {"-h", "--help"}, hidden = true)
      private boolean helpFlag;
focal_class.type: boolean
focal_class.var_name: helpFlag
focal_class.declarator: tags
focal_class.modifier: @CommandLine.Option(names = {"--tags"}, description = "Tag that need to write service")
      private
focal_class.original_string: @CommandLine.Option(names = {"--tags"}, description = "Tag that need to write service")
      private List<String> tags;
focal_class.type: List<String>
focal_class.var_name: tags
focal_class.declarator: operations
focal_class.modifier: @CommandLine.Option(names = {"--operations"}, description = "Operations that need to write service")
      private
focal_class.original_string: @CommandLine.Option(names = {"--operations"}, description = "Operations that need to write service")
      private List<String> operations;
focal_class.type: List<String>
focal_class.var_name: operations
focal_class.file: misc/openapi-ballerina/modules/openapi-to-ballerina-generator/src/main/java/org/ballerinalang/openapi/cmd/OpenApiGenServiceCmd.java
focal_class.identifier: OpenApiGenServiceCmd
focal_class.interfaces: implements BLauncherCmd
focal_class.class_method_signature: OpenApiGenServiceCmd.OpenApiGenServiceCmd()
focal_class.full_signature: public  OpenApiGenServiceCmd()
focal_class.identifier: OpenApiGenServiceCmd
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  OpenApiGenServiceCmd()
focal_class.class_method_signature: OpenApiGenServiceCmd.OpenApiGenServiceCmd(PrintStream outStream, String executionPath)
focal_class.full_signature: public  OpenApiGenServiceCmd(PrintStream outStream, String executionPath)
focal_class.identifier: OpenApiGenServiceCmd
focal_class.modifiers: public
focal_class.parameters: (PrintStream outStream, String executionPath)
focal_class.signature:  OpenApiGenServiceCmd(PrintStream outStream, String executionPath)
focal_class.class_method_signature: OpenApiGenServiceCmd.execute()
focal_class.full_signature: @Override public void execute()
focal_class.identifier: execute
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void execute()
focal_class.class_method_signature: OpenApiGenServiceCmd.getName()
focal_class.full_signature: @Override public String getName()
focal_class.identifier: getName
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getName()
focal_class.class_method_signature: OpenApiGenServiceCmd.printLongDesc(StringBuilder out)
focal_class.full_signature: @Override public void printLongDesc(StringBuilder out)
focal_class.identifier: printLongDesc
focal_class.modifiers: @Override public
focal_class.parameters: (StringBuilder out)
focal_class.return: void
focal_class.signature: void printLongDesc(StringBuilder out)
focal_class.class_method_signature: OpenApiGenServiceCmd.printUsage(StringBuilder out)
focal_class.full_signature: @Override public void printUsage(StringBuilder out)
focal_class.identifier: printUsage
focal_class.modifiers: @Override public
focal_class.parameters: (StringBuilder out)
focal_class.return: void
focal_class.signature: void printUsage(StringBuilder out)
focal_class.class_method_signature: OpenApiGenServiceCmd.setParentCmdParser(CommandLine parentCmdParser)
focal_class.full_signature: @Override public void setParentCmdParser(CommandLine parentCmdParser)
focal_class.identifier: setParentCmdParser
focal_class.modifiers: @Override public
focal_class.parameters: (CommandLine parentCmdParser)
focal_class.return: void
focal_class.signature: void setParentCmdParser(CommandLine parentCmdParser)
focal_method.body: @Override
      public void execute() {
          //User notification of using an experimental tool
          outStream.println(OpenApiMesseges.EXPERIMENTAL_FEATURE);
  
          CodeGenerator generator = new CodeGenerator();
  
          List<String> tag = new ArrayList<>();
          List<String> operation = new ArrayList<>();
          Filter filter = new Filter(tag, operation);
          tag.add("pet");
          operation.add("operation");
          //Check if cli help argument is present
          if (helpFlag) {
              String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(getName());
              outStream.println(commandUsageInfo);
              return;
          }
  
          //Check if a module name is present
          if (moduleArgs == null || moduleArgs.size() < 2) {
              throw LauncherUtils.createLauncherException(GEN_SERVICE_MODULE_ARGS_REQUIRED);
          } else {
              if (moduleArgs.get(0).trim().isEmpty()) {
                  throw LauncherUtils.createLauncherException(GEN_SERVICE_MODULE_REQUIRED);
              } else if (moduleArgs.get(1).trim().isEmpty()) {
                  throw LauncherUtils.createLauncherException(GEN_SERVICE_SERVICE_NAME_REQUIRED);
              }
          }
  
          //Check if an OpenApi definition is provided
          if (argList == null) {
              throw LauncherUtils.createLauncherException("An OpenApi definition file is required to generate the " +
                      "service. \nE.g: ballerina openapi gen-service " + moduleArgs.get(0) + ":"
                      + moduleArgs.get(1) + " <OpenApiContract>");
          }
  
          final Path projectRoot = ProjectDirs.findProjectRoot(Paths.get(executionPath));
          if (projectRoot == null) {
              throw LauncherUtils.createLauncherException(GEN_SERVICE_PROJECT_ROOT);
          }
          final Path sourceDirectory = projectRoot.resolve("src");
          final Path moduleDirectory = sourceDirectory.resolve(moduleArgs.get(0));
          final Path resourcesDirectory = Paths.get(moduleDirectory + "/resources");
          final Path testsDirectory = Paths.get(moduleDirectory + "/tests");
          final File openApiFile = new File(argList.get(0));
          final String openApiFilePath = openApiFile.getPath();
          Path resourcePath = Paths.get(resourcesDirectory + "/" + openApiFile.getName());
          Path relativeResourcePath = Paths.get("resources", openApiFile.getName());
  
          //Check provided OpenApi file is a valid and existing one
          if (Files.notExists(Paths.get(openApiFilePath))) {
              throw LauncherUtils.createLauncherException("Could not resolve a valid OpenApi" +
                      " contract in " + openApiFilePath);
          }
  
          if (Files.notExists(moduleDirectory)) {
              try {
                  Files.createDirectory(moduleDirectory);
              } catch (IOException e) {
                  throw LauncherUtils.createLauncherException(MODULE_DIRECTORY_EXCEPTION + "\n"
                          + e.getLocalizedMessage());
              }
          }
  
          File moduleMd = new File(moduleDirectory + "/Module.md");
          if (!moduleMd.exists()) {
              try {
                  boolean createMd = true;
                  createMd = moduleMd.createNewFile();
  
                  if (!createMd) {
                      throw LauncherUtils.createLauncherException(MODULE_MD_EXCEPTION);
                  }
              } catch (IOException e) {
                  throw LauncherUtils.createLauncherException(MODULE_MD_EXCEPTION + "\n"
                          + e.getLocalizedMessage());
              }
          }
  
          // Check for tests folder in ballerina module root
          if (Files.notExists(testsDirectory)) {
              try {
                  Files.createDirectory(testsDirectory);
              } catch (IOException e) {
                  throw LauncherUtils.createLauncherException(TESTS_DIRECTORY_EXCEPTION + "\n"
                          + e.getLocalizedMessage());
              }
          }
  
          if (skipBind) {
              try {
                  resourcePath = Paths.get(openApiFile.getCanonicalPath());
              } catch (IOException e) {
                  throw LauncherUtils.createLauncherException(e.getLocalizedMessage());
              }
          } else {
              // Check for resources folder in ballerina module root
              if (Files.notExists(resourcesDirectory)) {
                  try {
                      Files.createDirectory(resourcesDirectory);
                  } catch (IOException e) {
                      throw LauncherUtils.createLauncherException(RESOURCE_DIRECTORY_EXCEPTION + "\n"
                              + e.getLocalizedMessage());
                  }
              }
  
              // If OpenAPI contract by the same name doesn't exist in the resource folder continue to copy.
              // Else throw an exception.
              if (Files.notExists(resourcePath)) {
                  try {
                      Files.copy(Paths.get(openApiFilePath), resourcePath);
                  } catch (IOException e) {
                      throw LauncherUtils.createLauncherException(e.getLocalizedMessage());
                  }
              } else {
                  throw LauncherUtils.createLauncherException(DEFINITION_EXISTS
                          + " " + resourcesDirectory);
              }
          }
  
          if (output.isEmpty()) {
              output = executionPath;
          }
  
          //Set source package for the generated service
          generator.setSrcPackage(moduleArgs.get(0));
  
          //TODO Fix relative path compiler plugin issue
          //Set relative path for contract path which will be printed on the generated service bal file
          //Path absPath = Paths.get(resourcePath.toString());
          //Path basePath = Paths.get(output);
          //Path pathRelative = basePath.relativize(absPath);
  
          try {
              generator.generateService(executionPath, resourcePath.toString(), relativeResourcePath.toString(),
                      moduleArgs.get(1), output, filter);
          } catch (IOException | BallerinaOpenApiException e) {
              throw LauncherUtils.createLauncherException("Error occurred when generating service for openapi " +
                      "contract at " + argList.get(0) + ". " + e.getMessage() + ".");
          }
      }
focal_method.class_method_signature: OpenApiGenServiceCmd.execute()
focal_method.full_signature: @Override public void execute()
focal_method.identifier: execute
focal_method.invocations: println add add getCommandUsageInfo getName println size createLauncherException isEmpty trim get createLauncherException isEmpty trim get createLauncherException createLauncherException get get findProjectRoot get createLauncherException resolve resolve get get get get getPath get getName get getName notExists get createLauncherException notExists createDirectory createLauncherException getLocalizedMessage exists createNewFile createLauncherException createLauncherException getLocalizedMessage notExists createDirectory createLauncherException getLocalizedMessage get getCanonicalPath createLauncherException getLocalizedMessage notExists createDirectory createLauncherException getLocalizedMessage notExists copy get createLauncherException getLocalizedMessage createLauncherException isEmpty setSrcPackage get generateService toString toString get createLauncherException get getMessage
focal_method.modifiers: @Override public
focal_method.parameters: ()
focal_method.return: void
focal_method.signature: void execute()