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

The following examples show how to use io.swagger.models.Path#get() . 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: SwaggerUtils.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * Create a swagger definition from data-service resource details.
 *
 * @param axisResourceMap AxisResourceMap containing resource details.
 * @param dataServiceName Name of the data service.
 * @param transports      Transports supported from the data-service.
 * @param serverConfig    Server config details.
 * @param isJSON          result format JSON or YAML.
 * @return Swagger definition as string.
 * @throws AxisFault Error occurred while fetching the host address.
 */
private static String createSwaggerFromDefinition(AxisResourceMap axisResourceMap, String dataServiceName,
                                                  List<String> transports, MIServerConfig serverConfig,
                                                  boolean isJSON)
        throws AxisFault {

    Swagger swaggerDoc = new Swagger();
    addSwaggerInfoSection(dataServiceName, transports, serverConfig, swaggerDoc);

    Map<String, Path> paths = new HashMap<>();

    for (Map.Entry<String, AxisResource> entry : axisResourceMap.getResources().entrySet()) {
        Path path = new Path();
        for (String method : entry.getValue().getMethods()) {
            Operation operation = new Operation();
            List<AxisResourceParameter> parameterList = entry.getValue().getResourceParameterList(method);
            generatePathAndQueryParameters(method, operation, parameterList);
            // Adding a sample request payload for methods except GET.
            generateSampleRequestPayload(method, operation, parameterList);
            Response response = new Response();
            response.description("this is the default response");
            operation.addResponse("default", response);
            switch (method) {
                case "GET":
                    path.get(operation);
                    break;
                case "POST":
                    path.post(operation);
                    break;
                case "DELETE":
                    path.delete(operation);
                    break;
                case "PUT":
                    path.put(operation);
                    break;
                default:
                    throw new AxisFault("Invalid method \"" + method + "\" detected in the data-service");
            }
        }
        String contextPath = entry.getKey().startsWith("/") ? entry.getKey() : "/" + entry.getKey();
        paths.put(contextPath, path);
    }
    swaggerDoc.setPaths(paths);
    if (isJSON) return Json.pretty(swaggerDoc);
    try {
        return Yaml.pretty().writeValueAsString(swaggerDoc);
    } catch (JsonProcessingException e) {
        logger.error("Error occurred while creating the YAML configuration", e);
        return null;
    }
}
 
Example 2
Source File: ODLPathHandler.java    From yang2swagger with Eclipse Public License 1.0 4 votes vote down vote up
protected Path operationalOperations(DataSchemaNode node, PathSegment pathCtx) {
    final Path path = new Path();
    path.get(new GetOperationGenerator(pathCtx, dataObjectBuilder).execute(node).tags(tags(pathCtx)));
    return path;
}
 
Example 3
Source File: SwaggerService.java    From ob1k with Apache License 2.0 4 votes vote down vote up
private Swagger buildSwagger(final Request request) {
  final Swagger swagger = new Swagger();
  swagger.host(request.getHeader("Host"));
  swagger.info(buildInfo());                          


  Set<ISwaggerAware> invoked = Sets.newHashSet();
  for (final Map.Entry<String, Map<HttpRequestMethodType, ServerEndpointView>> entry :
          serviceRegistry.getRegisteredEndpoints().entrySet()) {
    final Path path = new Path();
    for (final Map.Entry<HttpRequestMethodType, ServerEndpointView> endpointEntry : entry.getValue().entrySet()) {
      final HttpRequestMethodType methodType = endpointEntry.getKey();
      final String key = entry.getKey();
      final ServerEndpointView endpoint = endpointEntry.getValue();
      final Service service = endpoint.service();
      if (!ignoreEndpoint(endpoint)) {
        final Tag tag = buildTag(endpoint.getMethod().getDeclaringClass());
        swagger.addTag(tag);
        if (service instanceof ISwaggerAware) {
          ISwaggerAware swaggerAware = (ISwaggerAware) service;
          if(invoked.add(swaggerAware)) {
            swaggerAware.invoke(swagger, key);
          }
        } else {
          switch (methodType) {
            case GET:
            case ANY:
              path.get(buildOperation(endpoint, tag, methodType));
              break;
            case POST:
              path.post(buildOperation(endpoint, tag, methodType));
              break;
            case PUT:
              path.put(buildOperation(endpoint, tag, methodType));
              break;
            case DELETE:
              path.delete(buildOperation(endpoint, tag, methodType));
              break;
            default:
              throw new UnsupportedOperationException("Unsupported method type " + methodType);
          }
          swagger.path(key, path);
        }
      }
    }
  }
  return swagger;
}