Package ai.wanaku.cli.main.support
Class ToolsGenerateHelper
java.lang.Object
ai.wanaku.cli.main.support.ToolsGenerateHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddHttpMethodProperty(InputSchema inputSchema, String method) Adds the HTTP method as a property to the input schema.static StringdetermineBaseUrl(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.static StringdetermineOperationUri(io.swagger.v3.oas.models.Operation operation, String baseUrl) Determines the URI to use for an operation.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.static PrintWritergetOutputPrintWriter2(String output) Gets a PrintWriter for the specified output location.static StringinterpolateServerUrl(io.swagger.v3.oas.models.servers.Server server, Map<String, String> variables) Interpolates the server URL with the provided variables.static io.swagger.v3.oas.models.OpenAPIloadAndResolveOpenAPI(String specLocation) Loads and resolves an OpenAPI specification from the given location.static ToolReferenceoperation2ToolReference(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.static Propertyparameter2Property(io.swagger.v3.oas.models.parameters.Parameter parameter) Converts an OpenAPI parameter to a tool reference property.static InputSchemaparameters2InputSchema(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.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.static StringtoolReferenceUrl(String baseUrl, String path) Creates a URL template for the tool reference by replacing path parameters with the tool reference format.static voidwriteOutput(List<ToolReference> toolReferences, String output) Writes the tool references to the specified output location as JSON.
-
Method Details
-
loadAndResolveOpenAPI
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 objectserverUrl- 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 objectbaseUrl- The base URL to use for API calls- Returns:
- A list of tool references
-
writeOutput
Writes the tool references to the specified output location as JSON.- Parameters:
toolReferences- The list of tool references to writeoutput- 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 APIpath- The path from the OpenAPI specificationpathItem- 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 operationoperation- The Operation to convertbaseUrl- The base URL for the APIpath- The path from the OpenAPI specificationmethod- 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 objectbaseUrl- The default base URL to use- Returns:
- The URI to use for this operation
-
addHttpMethodProperty
Adds the HTTP method as a property to the input schema.- Parameters:
inputSchema- The input schema to modifymethod- 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 specificationrequestBody- The request body from the OpenAPI specification- Returns:
- An InputSchema object representing the parameters and request body
-
parameter2Property
Converts an OpenAPI parameter to a tool reference property.- Parameters:
parameter- The OpenAPI parameter to convert- Returns:
- A Property object representing the parameter
-
toolReferenceUrl
Creates a URL template for the tool reference by replacing path parameters with the tool reference format.- Parameters:
baseUrl- The base URL for the APIpath- 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 variablesvariables- Map of variable names to values (may be null or empty)- Returns:
- The interpolated server URL
-
getOutputPrintWriter2
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
-