Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export SNOWFLAKE_PAT=abcd...
### 1. Download REST API specs for Snowflake and unzip to the `provider-dev/source` directory

```bash
rm -rf ./provider-dev/source/*
wget https://github.com/snowflakedb/snowflake-rest-api-specs/archive/refs/heads/main.zip
mkdir -p provider-dev/source
unzip main.zip -d provider-dev/source
Expand Down Expand Up @@ -57,7 +58,6 @@ bash ./bin/openapi-to-stackql.sh convert \
--skip common.yaml
```

cortex-analyst.yaml,cortex-inference.yaml,cortex-search-service.yaml
### 5. Post process the specs
Post process the specs to remove redundant reference paths:

Expand Down
6 changes: 6 additions & 0 deletions openapi_to_stackql/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def run(input_dir: str, output_dir: str, config_path: str, provider_id: str, ser
os.remove(file_path)
print(f"🧹 Cleared all files in {services_path}")

# delete provider.yaml file
provider_manifest_file = os.path.join(output_dir, version, "provider.yaml")
if os.path.isfile(provider_manifest_file):
os.remove(provider_manifest_file)
print(f"🧹 Deleted {provider_manifest_file}")

manifest = load_manifest(config_path)

provider_services = {}
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@stackql/provider-utils": "^0.1.3"
"@stackql/provider-utils": "^0.1.4"
},
"engines": {
"node": ">=14.16.0"
Expand Down
506 changes: 253 additions & 253 deletions provider-dev/config/snowflake.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions provider-dev/docgen/provider-data/headerContent1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ keywords:
description: Query, deploy and manage Snowflake resources using SQL
custom_edit_url: null
image: /img/providers/snowflake/stackql-snowflake-provider-featured-image.png
id: 'provider-intro'
---

import CopyableCode from '@site/src/components/CopyableCode/CopyableCode';
Expand Down
76 changes: 30 additions & 46 deletions provider-dev/scripts/post_process.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
import sys
import re
import sys

services_dir = sys.argv[1]

#
# Process all yaml files first for common replacements
#
for filename in os.listdir(services_dir):
if not filename.endswith('.yaml'):
continue
Expand All @@ -13,54 +15,36 @@

with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()

# Common replacements for all files
if './common.yaml' in content or 'common.yaml' in content:
content = content.replace('./common.yaml', "'").replace('common.yaml', "'")

with open(file_path, 'w', encoding='utf-8') as f:
f.write(content)
print(f"✅ Replaced common.yaml references in: {filename}")
content = content.replace('./common.yaml', '').replace('common.yaml', '')

# Special processing for cortex-inference.yaml
cortex_file_path = os.path.join(services_dir, 'cortex-inference.yaml')
if os.path.exists(cortex_file_path):
with open(cortex_file_path, 'r', encoding='utf-8') as f:
content = f.read()

# 1. Add the Any schema to components/schemas
if 'components:' in content and 'schemas:' in content:
# Find where to insert the Any schema
schemas_pattern = re.compile(r'(components:\s*\n\s*schemas:\s*\n)', re.MULTILINE)
match = schemas_pattern.search(content)

if match:
any_schema = """ Any:
description: Generic schema that accepts any value
nullable: true
additionalProperties: true
"""
# Insert the Any schema after the schemas section start
content = content[:match.end()] + any_schema + content[match.end():]
print("✅ Added Any schema to components/schemas")

# 2. Replace all references to common-cortex-tool.yaml
pattern = r'common-cortex-tool\.yaml#/components/schemas/[a-zA-Z0-9]+'
replacements = 0

for match in re.finditer(pattern, content):
content = content.replace(match.group(0), '#/components/schemas/Any')
replacements += 1

content = content.replace('#/components/schemas/Any', "'#/components/schemas/Any'")

print(f"✅ Replaced {replacements} references to common-cortex-tool.yaml schemas")

# Write the changes back to the file
with open(cortex_file_path, 'w', encoding='utf-8') as f:
# hack for this non existent file
if filename == "cortex-inference.yaml":
content = re.sub(r'common-cortex-tool\.yaml#/components/schemas/(\w+)', r"'#/components/schemas/\1'", content)
# pattern = r'common-cortex-tool\.yaml#/components/schemas/\w+'
# matches = re.findall(pattern, content)

# if matches:
# print(f"\n=== MATCHES IN {filename} ===")
# for match in matches:
# print(f"Found: {match}")
# else:
# print(f"No matches found in {filename}")


lines = content.split('\n')
for i in range(len(lines)):
# Find all unquoted $ref entries and quote them (without escaping)
if '$ref: #' in lines[i] and not ('$ref: \'#' in lines[i] or '$ref: "#' in lines[i]):
ref_part = lines[i].split('$ref: ')[1]
lines[i] = lines[i].replace('$ref: ' + ref_part, '$ref: \'' + ref_part + '\'')

content = '\n'.join(lines)

with open(file_path, 'w', encoding='utf-8') as f:
f.write(content)
print(f"✅ Updated cortex-inference.yaml")
else:
print("⚠️ cortex-inference.yaml not found in the specified directory")
print(f"✅ Replaced common.yaml references in: {filename}")

print("✅ All processing completed")
151 changes: 150 additions & 1 deletion provider-dev/scripts/pre_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,150 @@
import sys
import copy

# declare custom inference schemas
custom_schemas = {
"TextContent": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["text"]
},
"text": {
"type": "string"
}
},
"required": ["type", "text"]
},
"ToolResults": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["tool_results"]
},
"tool_results": {
"type": "object",
"properties": {
"tool_use_id": {
"type": "string"
},
"name": {
"type": "string"
},
"content": {
"type": "array",
"items": {
"type": "object"
}
}
}
}
},
"required": ["type", "tool_results"]
},
"ToolUse": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["tool_use"]
},
"tool_use": {
"type": "object",
"properties": {
"tool_use_id": {
"type": "string"
},
"name": {
"type": "string"
},
"input": {
"type": "object"
}
}
}
},
"required": ["type", "tool_use"]
},
"StreamingTextContent": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["text"]
},
"text": {
"type": "string"
}
},
"required": ["type", "text"]
},
"StreamingToolUse": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["tool_use"]
},
"tool_use": {
"type": "object",
"properties": {
"tool_use_id": {
"type": "string"
},
"name": {
"type": "string"
},
"input": {
"type": "object"
}
}
}
},
"required": ["type", "tool_use"]
},
"Tool": {
"type": "object",
"properties": {
"tool_spec": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"input_schema": {
"type": "object"
}
}
}
},
"required": ["tool_spec"]
},
"ToolChoice": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["auto", "required", "tool"]
},
"name": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["type"]
}
}

def load_yaml(filepath):
with open(filepath, "r", encoding="utf-8") as f:
return yaml.safe_load(f)
Expand Down Expand Up @@ -84,7 +228,12 @@ def run(input_dir, keywords_to_rename=None):

# Merge components as in the original script
merge_components(spec, common_spec)


if filename == "cortex-inference.yaml":
print(f"🔧 Adding schemas for: {filename}")
for schema_name, schema_def in custom_schemas.items():
spec["components"]["schemas"][schema_name] = schema_def

# Rename path parameters in URL paths
if 'paths' in spec:
updated_paths = {}
Expand Down
Loading
Loading