Class ToolsGenerateHelper

java.lang.Object
ai.wanaku.cli.main.support.ToolsGenerateHelper

public class ToolsGenerateHelper extends Object
  • Method Details

    • loadAndResolveOpenAPI

      public static io.swagger.v3.oas.models.OpenAPI loadAndResolveOpenAPI(String specLocation)
      Loads and resolves an OpenAPI specification from the given location.
      Parameters:
      specLocation - The file path or URL of the OpenAPI specification
      Returns:
      A fully resolved OpenAPI object
    • determineBaseUrl

      public static String determineBaseUrl(io.swagger.v3.oas.models.OpenAPI openAPI, String serverUrl, Integer serverIndex, Map<String,String> serverVariables)
      Determines the base URL to use for API calls based on available information. First checks if a server URL is explicitly provided, then falls back to servers defined in the OpenAPI spec.
      Parameters:
      openAPI - The OpenAPI specification object
      serverUrl - A server URL that overrides the ones in the OpenAPI spec (may be null)
      serverIndex - The index of the server to use from the OpenAPI spec's servers list (if serverUrl is not provided)
      serverVariables - Map of variable names to values for server URL templating
      Returns:
      The resolved base URL for API calls
    • generateToolReferences

      public static List<ToolReference> generateToolReferences(io.swagger.v3.oas.models.OpenAPI openAPI, String baseUrl)
      Generates tool references for all paths and operations in the OpenAPI specification.
      Parameters:
      openAPI - The OpenAPI specification object
      baseUrl - The base URL to use for API calls
      Returns:
      A list of tool references
    • writeOutput

      public static void writeOutput(List<ToolReference> toolReferences, String output) throws Exception
      Writes the tool references to the specified output location as JSON.
      Parameters:
      toolReferences - The list of tool references to write
      output - The output path or null to write to standard output
      Throws:
      Exception - If an error occurs during writing
    • pathItem2ToolReferences

      public static List<ToolReference> pathItem2ToolReferences(String baseUrl, String path, io.swagger.v3.oas.models.PathItem pathItem)
      Converts a PathItem and its operations into a list of tool references.
      Parameters:
      baseUrl - The base URL for the API
      path - The path from the OpenAPI specification
      pathItem - The PathItem object containing the operations
      Returns:
      A list of tool references, one for each operation in the PathItem
    • operation2ToolReference

      public static ToolReference operation2ToolReference(io.swagger.v3.oas.models.PathItem pathItem, io.swagger.v3.oas.models.Operation operation, String baseUrl, String path, String method)
      Converts an operation to a tool reference.
      Parameters:
      pathItem - The PathItem containing the operation
      operation - The Operation to convert
      baseUrl - The base URL for the API
      path - The path from the OpenAPI specification
      method - The HTTP method for this operation
      Returns:
      A ToolReference representing the operation
    • determineOperationUri

      public static String determineOperationUri(io.swagger.v3.oas.models.Operation operation, String baseUrl)
      Determines the URI to use for an operation. First checks if a base URL is provided, then falls back to servers defined in the operation.
      Parameters:
      operation - The Operation object
      baseUrl - The default base URL to use
      Returns:
      The URI to use for this operation
    • addHttpMethodProperty

      public static void addHttpMethodProperty(InputSchema inputSchema, String method)
      Adds the HTTP method as a property to the input schema.
      Parameters:
      inputSchema - The input schema to modify
      method - The HTTP method to add
    • parameters2InputSchema

      public static InputSchema parameters2InputSchema(List<io.swagger.v3.oas.models.parameters.Parameter> parameters, io.swagger.v3.oas.models.parameters.RequestBody requestBody)
      Converts OpenAPI parameters and request body to an input schema for the tool reference.
      Parameters:
      parameters - The list of parameters from the OpenAPI specification
      requestBody - The request body from the OpenAPI specification
      Returns:
      An InputSchema object representing the parameters and request body
    • parameter2Property

      public static Property parameter2Property(io.swagger.v3.oas.models.parameters.Parameter parameter)
      Converts an OpenAPI parameter to a tool reference property.
      Parameters:
      parameter - The OpenAPI parameter to convert
      Returns:
      A Property object representing the parameter
    • toolReferenceUrl

      public static String toolReferenceUrl(String baseUrl, String path)
      Creates a URL template for the tool reference by replacing path parameters with the tool reference format.
      Parameters:
      baseUrl - The base URL for the API
      path - The path from the OpenAPI specification
      Returns:
      A URL template for the tool reference
    • interpolateServerUrl

      public static String interpolateServerUrl(io.swagger.v3.oas.models.servers.Server server, Map<String,String> variables)
      Interpolates the server URL with the provided variables. Uses default values for any variables not explicitly provided.
      Parameters:
      server - The Server object containing the URL template and variables
      variables - Map of variable names to values (may be null or empty)
      Returns:
      The interpolated server URL
    • getOutputPrintWriter2

      public static PrintWriter getOutputPrintWriter2(String output) throws Exception
      Gets a PrintWriter for the specified output location. If output is null or empty, returns a PrintWriter for standard output. Otherwise, returns a PrintWriter for the specified file.
      Parameters:
      output - The output path or null for standard output
      Returns:
      A PrintWriter for the specified output
      Throws:
      Exception - If the output file cannot be created or written to