コード例 #1
0
  @Test
  public void testGenerateUniqueOperationIds() {
    final File output = folder.getRoot();

    final Swagger swagger =
        new SwaggerParser().read("src/test/resources/2_0/duplicateOperationIds.yaml");
    CodegenConfig codegenConfig = new JavaClientCodegen();
    codegenConfig.setOutputDir(output.getAbsolutePath());

    ClientOptInput clientOptInput =
        new ClientOptInput().opts(new ClientOpts()).swagger(swagger).config(codegenConfig);

    DefaultGenerator generator = new DefaultGenerator();
    generator.opts(clientOptInput);

    Map<String, List<CodegenOperation>> paths = generator.processPaths(swagger.getPaths());
    Set<String> opIds = new HashSet<String>();
    for (String path : paths.keySet()) {
      List<CodegenOperation> ops = paths.get(path);
      for (CodegenOperation op : ops) {
        assertFalse(opIds.contains(op.operationId));
        opIds.add(op.operationId);
      }
    }
  }
コード例 #2
0
  @Test
  public void testSecurityWithoutGlobal() throws Exception {
    final Swagger swagger = new SwaggerParser().read("src/test/resources/2_0/petstore.json");
    CodegenConfig codegenConfig = new JavaClientCodegen();

    ClientOptInput clientOptInput =
        new ClientOptInput().opts(new ClientOpts()).swagger(swagger).config(codegenConfig);

    DefaultGenerator gen = new DefaultGenerator();
    gen.opts(clientOptInput);
    Map<String, List<CodegenOperation>> paths = gen.processPaths(swagger.getPaths());

    CodegenSecurity cs, apiKey, petstoreAuth;

    // security of "getPetById": api_key
    CodegenOperation getPetById = findCodegenOperationByOperationId(paths, "getPetById");
    assertEquals(getPetById.authMethods.size(), 2);
    cs = getPetById.authMethods.get(0);
    if ("api_key".equals(cs.name)) {
      apiKey = cs;
      petstoreAuth = getPetById.authMethods.get(1);
    } else {
      petstoreAuth = cs;
      apiKey = getPetById.authMethods.get(1);
    }
    assertEquals(petstoreAuth.name, "petstore_auth");
    assertEquals(petstoreAuth.type, "oauth2");
    assertEquals(apiKey.name, "api_key");
    assertEquals(apiKey.type, "apiKey");

    // security of "updatePetWithForm": petstore_auth
    CodegenOperation updatePetWithForm =
        findCodegenOperationByOperationId(paths, "updatePetWithForm");
    assertEquals(updatePetWithForm.authMethods.size(), 1);
    petstoreAuth = updatePetWithForm.authMethods.iterator().next();
    assertEquals(petstoreAuth.name, "petstore_auth");
    assertEquals(petstoreAuth.type, "oauth2");

    // security of "loginUser": null (no global security either)
    CodegenOperation loginUser = findCodegenOperationByOperationId(paths, "loginUser");
    assertNull(loginUser.authMethods);
  }