Java Code Examples for io.swagger.models.Path#getOperations()

The following examples show how to use io.swagger.models.Path#getOperations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Reader.java    From dorado with Apache License 2.0 6 votes vote down vote up
private boolean existOperationId(String operationId) {
	if (swagger == null) {
		return false;
	}
	if (swagger.getPaths() == null || swagger.getPaths().isEmpty()) {
		return false;
	}
	for (Path path : swagger.getPaths().values()) {
		for (Operation op : path.getOperations()) {
			if (operationId.equalsIgnoreCase(op.getOperationId())) {
				return true;
			}
		}
	}
	return false;
}
 
Example 2
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param swagger
 * @return
 */
private List<InterfaceDiagram> processSwaggerPaths(Swagger swagger) {
	LOGGER.entering(LOGGER.getName(), "processSwaggerPaths");
	List<InterfaceDiagram> interfaceDiagrams = new ArrayList<InterfaceDiagram>();
	Map<String, Path> paths = swagger.getPaths();

	for (Map.Entry<String, Path> entry : paths.entrySet()) {
		Path pathObject = entry.getValue();

		LOGGER.info("Processing Path --> " + entry.getKey());

		List<Operation> operations = pathObject.getOperations();
		String uri = entry.getKey();

		for (Operation operation : operations) {
			interfaceDiagrams.add(getInterfaceDiagram(operation, uri));
		}
	}

	LOGGER.exiting(LOGGER.getName(), "processSwaggerPaths");
	return interfaceDiagrams;
}
 
Example 3
Source File: RestControllerProcessorTest.java    From herd with Apache License 2.0 6 votes vote down vote up
@Test
public void test_3() throws Exception
{
    Swagger swagger = new Swagger();
    String restJavaPackage = "org.finra.herd.swaggergen.test.restControllerProcessor.case3";
    String tagPatternTemplate = "(?<tag>.+?)RestController";
    Class<?> modelErrorClass = null;
    new RestControllerProcessor(LOG, swagger, restJavaPackage, tagPatternTemplate, modelErrorClass);
    List<String> operationIds = new ArrayList<>();
    for (Path path : swagger.getPaths().values())
    {
        for (Operation operation : path.getOperations())
        {
            operationIds.add(operation.getOperationId());
        }
    }
    assertEquals(2, operationIds.size());
    assertTrue(operationIds.contains("Test3.duplicate"));
    assertTrue(operationIds.contains("Test3.duplicate1"));
}
 
Example 4
Source File: SwaggerInventory.java    From swagger-parser with Apache License 2.0 6 votes vote down vote up
public void process(Path path) {
    this.paths.add(path);
    Iterator var2;
    if(path.getParameters() != null) {
        var2 = path.getParameters().iterator();

        while(var2.hasNext()) {
            Parameter operation = (Parameter)var2.next();
            this.process(operation);
        }
    }

    if(path.getOperations() != null) {
        var2 = path.getOperations().iterator();

        while(var2.hasNext()) {
            Operation operation1 = (Operation)var2.next();
            this.process(operation1);
        }
    }

}
 
Example 5
Source File: AbstractJavaCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
    if (swagger == null || swagger.getPaths() == null){
        return;
    }
    for (String pathname : swagger.getPaths().keySet()) {
        Path path = swagger.getPath(pathname);
        if (path.getOperations() == null){
            continue;
        }
        for (Operation operation : path.getOperations()) {
            boolean hasFormParameters = false;
            boolean hasBodyParameters = false;
            for (Parameter parameter : operation.getParameters()) {
                if (parameter instanceof FormParameter) {
                    hasFormParameters = true;
                }
                if (parameter instanceof BodyParameter) {
                    hasBodyParameters = true;
                }
            }
            if (hasBodyParameters || hasFormParameters){
                String defaultContentType = hasFormParameters ? "application/x-www-form-urlencoded" : "application/json";
                String contentType =  operation.getConsumes() == null || operation.getConsumes().isEmpty() ? defaultContentType : operation.getConsumes().get(0);
                operation.setVendorExtension("x-contentType", contentType);
            }
            String accepts = getAccept(operation);
            operation.setVendorExtension("x-accepts", accepts);
        }
    }
}
 
Example 6
Source File: JMeterCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
  if (swagger != null && swagger.getPaths() != null) {
    for (String pathname : swagger.getPaths().keySet()) {
      Path path = swagger.getPath(pathname);
      if (path.getOperations() != null) {
        for (Operation operation : path.getOperations()) {
          String pathWithDollars = pathname.replaceAll("\\{", "\\$\\{");
          operation.setVendorExtension("x-path", pathWithDollars);
        }
      }
    }
  }
}
 
Example 7
Source File: SwaggerUtils.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static void correctResponses(Swagger swagger) {
  if (swagger.getPaths() == null) {
    return;
  }

  for (Path path : swagger.getPaths().values()) {
    for (Operation operation : path.getOperations()) {
      correctResponses(operation);
    }
  }
}
 
Example 8
Source File: AddSecurityDefinitions.java    From yang2swagger with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void accept(Swagger swagger) {
    swagger.securityDefinition(securityDefinitionName, securityDefinition);

    for(Path p : swagger.getPaths().values()) {
        for(Operation o : p.getOperations()) {
            o.addSecurity(securityDefinitionName, Collections.emptyList());
        }
    }
}
 
Example 9
Source File: BackendBuilder.java    From api-compiler with Apache License 2.0 4 votes vote down vote up
@Override
public void addFromSwagger(Service.Builder serviceBuilder, Swagger swagger) {
  final Backend.Builder backendBuilder = serviceBuilder.getBackendBuilder();

  for (final Map.Entry<String, Path> entry : swagger.getPaths().entrySet()) {
    final Path path = entry.getValue();
    for (final Operation operation : path.getOperations()) {
      if (Strings.isNullOrEmpty(operation.getOperationId())) {
        // Silently skip if the operation is invalid
        continue;
      }
      final String selector =
          namespacePrefix + NameConverter.operationIdToMethodName(operation.getOperationId());

      final String backendUrl =
          VendorExtensionUtils.getExtensionValueOrNull(
              operation.getVendorExtensions(),
              String.class,
              this.diagCollector,
              ExtensionNames.BACKEND_URL_EXTENSION);
      final Integer backendDeadline =
          VendorExtensionUtils.getExtensionValueOrNull(
              operation.getVendorExtensions(),
              Integer.class,
              this.diagCollector,
              ExtensionNames.BACKEND_DEADLINE_EXTENSION);
      if (backendUrl != null) {
        final BackendRule.Builder ruleBuilder = BackendRule.newBuilder()
            .setSelector(selector)
            .setAddress(backendUrl);
        if (backendDeadline != null) {
          ruleBuilder.setDeadline(backendDeadline);
        }
        backendBuilder.addRules(ruleBuilder);
      }
    }
  }

  if (backendBuilder.getRulesList().isEmpty()) {
    serviceBuilder.clearBackend();
  }
}