add tags to swagger
This commit is contained in:
@@ -16,7 +16,60 @@
|
||||
"tabs": [
|
||||
{
|
||||
"tab": "API Documentation",
|
||||
"openapi": "https://raw.githubusercontent.com/chatwoot/chatwoot/90c600acd94cfe2f5c41d5cedebdec9534cba2d7/swagger/swagger.json"
|
||||
"groups": [
|
||||
{
|
||||
"group": "Platform API",
|
||||
"description": "APIs for managing platform aspects of Chatwoot",
|
||||
"includeTags": [
|
||||
"Accounts",
|
||||
"Account Users",
|
||||
"AgentBots",
|
||||
"Users"
|
||||
],
|
||||
"openapi": "https://raw.githubusercontent.com/chatwoot/chatwoot/90c600acd94cfe2f5c41d5cedebdec9534cba2d7/swagger/tag_groups/platform_swagger.json"
|
||||
},
|
||||
{
|
||||
"group": "Application API",
|
||||
"description": "APIs for managing application aspects of Chatwoot",
|
||||
"includeTags": [
|
||||
"Account AgentBots",
|
||||
"Agents",
|
||||
"Canned Responses",
|
||||
"Contacts",
|
||||
"Conversations",
|
||||
"Custom Attributes",
|
||||
"Custom Filters",
|
||||
"Inboxes",
|
||||
"Integrations",
|
||||
"Messages",
|
||||
"Profile",
|
||||
"Reports",
|
||||
"Teams",
|
||||
"Webhooks",
|
||||
"Automation Rule",
|
||||
"Help Center"
|
||||
],
|
||||
"openapi": "https://raw.githubusercontent.com/chatwoot/chatwoot/90c600acd94cfe2f5c41d5cedebdec9534cba2d7/swagger/tag_groups/application_swagger.json"
|
||||
},
|
||||
{
|
||||
"group": "Client API",
|
||||
"description": "APIs for client applications",
|
||||
"includeTags": [
|
||||
"Contacts API",
|
||||
"Conversations API",
|
||||
"Messages API"
|
||||
],
|
||||
"openapi": "https://raw.githubusercontent.com/chatwoot/chatwoot/90c600acd94cfe2f5c41d5cedebdec9534cba2d7/swagger/tag_groups/client_swagger.json"
|
||||
},
|
||||
{
|
||||
"group": "Other APIs",
|
||||
"description": "Other Chatwoot APIs",
|
||||
"includeTags": [
|
||||
"CSAT Survey Page"
|
||||
],
|
||||
"openapi": "https://raw.githubusercontent.com/chatwoot/chatwoot/90c600acd94cfe2f5c41d5cedebdec9534cba2d7/swagger/tag_groups/other_swagger.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -25,4 +78,4 @@
|
||||
"github": "https://github.com/chatwoot",
|
||||
"linkedin": "https://www.linkedin.com/company/chatwoot"
|
||||
}
|
||||
}
|
||||
}
|
||||
+78
-37
@@ -30,48 +30,89 @@ namespace :swagger do
|
||||
base_path = Rails.root.join('swagger')
|
||||
tag_groups_path = base_path.join('tag_groups')
|
||||
|
||||
Dir.chdir(tag_groups_path) do
|
||||
# Build for platform
|
||||
platform_yaml = YAML.safe_load(File.open('platform.yml'))
|
||||
platform_build = JsonRefs.call(
|
||||
platform_yaml,
|
||||
resolve_local_ref: false,
|
||||
resolve_file_ref: true,
|
||||
logging: true
|
||||
)
|
||||
File.write('platform_swagger.json', JSON.pretty_generate(platform_build))
|
||||
# Load the full swagger specification
|
||||
full_spec = JSON.parse(File.read(base_path.join('swagger.json')))
|
||||
|
||||
# Load the tag groups from index.yml
|
||||
swagger_index = YAML.safe_load(File.open(base_path.join('index.yml')))
|
||||
tag_groups = swagger_index['x-tagGroups']
|
||||
|
||||
# Process each tag group
|
||||
tag_groups.each do |tag_group|
|
||||
group_name = tag_group['name']
|
||||
tags = tag_group['tags']
|
||||
|
||||
# Build for application
|
||||
application_yaml = YAML.safe_load(File.open('application.yml'))
|
||||
application_build = JsonRefs.call(
|
||||
application_yaml,
|
||||
resolve_local_ref: false,
|
||||
resolve_file_ref: true,
|
||||
logging: true
|
||||
)
|
||||
File.write('application_swagger.json', JSON.pretty_generate(application_build))
|
||||
# Create a copy of the full spec for this tag group
|
||||
tag_spec = full_spec.dup
|
||||
|
||||
# Build for client
|
||||
client_yaml = YAML.safe_load(File.open('client.yml'))
|
||||
client_build = JsonRefs.call(
|
||||
client_yaml,
|
||||
resolve_local_ref: false,
|
||||
resolve_file_ref: true,
|
||||
logging: true
|
||||
)
|
||||
File.write('client_swagger.json', JSON.pretty_generate(client_build))
|
||||
# Filter paths to only include those with operations tagged with any of our tags
|
||||
filtered_paths = {}
|
||||
|
||||
# Build for others
|
||||
others_yaml = YAML.safe_load(File.open('others.yml'))
|
||||
others_build = JsonRefs.call(
|
||||
others_yaml,
|
||||
resolve_local_ref: false,
|
||||
resolve_file_ref: true,
|
||||
logging: true
|
||||
)
|
||||
File.write('other_swagger.json', JSON.pretty_generate(others_build))
|
||||
full_spec['paths'].each do |path, path_item|
|
||||
# Check if any operation in this path has a tag from our group
|
||||
operations_with_our_tags = false
|
||||
|
||||
path_item.each do |method, operation|
|
||||
next unless operation.is_a?(Hash) && operation['tags']
|
||||
|
||||
# Check if any of our tags are in the operation's tags
|
||||
if (operation['tags'] & tags).any?
|
||||
operations_with_our_tags = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# If we found operations with our tags, add the path to our filtered paths
|
||||
if operations_with_our_tags
|
||||
filtered_paths[path] = path_item
|
||||
end
|
||||
end
|
||||
|
||||
# Replace the paths in our tag-specific spec
|
||||
tag_spec['paths'] = filtered_paths
|
||||
|
||||
# Filter tags to only include those in our group
|
||||
tag_spec['tags'] = full_spec['tags'].select { |tag| tags.include?(tag['name']) }
|
||||
|
||||
# Write the tag-specific spec to file
|
||||
output_file = "#{group_name.downcase}_swagger.json"
|
||||
output_file = "other_swagger.json" if group_name.downcase == 'others'
|
||||
|
||||
File.write(tag_groups_path.join(output_file), JSON.pretty_generate(tag_spec))
|
||||
end
|
||||
|
||||
puts 'Tag-specific swagger files generated successfully.'
|
||||
end
|
||||
|
||||
desc 'build swagger files and create symlinks in developer-docs'
|
||||
task build_for_docs: :environment do
|
||||
# First, build the swagger files
|
||||
Rake::Task['swagger:build'].invoke
|
||||
|
||||
# Create directories in developer-docs if they don't exist
|
||||
dev_docs_public = Rails.root.join('developer-docs', 'public')
|
||||
FileUtils.mkdir_p(File.join(dev_docs_public, 'swagger', 'tag_groups'))
|
||||
|
||||
# Create symlinks to the swagger files
|
||||
tag_groups_path = Rails.root.join('swagger', 'tag_groups')
|
||||
|
||||
# Symlink each JSON file
|
||||
puts 'Creating symlinks for developer-docs...'
|
||||
|
||||
symlink_files = %w[platform_swagger.json application_swagger.json client_swagger.json other_swagger.json]
|
||||
symlink_files.each do |file|
|
||||
source = File.join(tag_groups_path, file)
|
||||
target = File.join(dev_docs_public, 'swagger', 'tag_groups', file)
|
||||
|
||||
# Remove existing file or symlink
|
||||
FileUtils.rm_f(target)
|
||||
|
||||
# Create a relative symbolic link
|
||||
rel_path = Pathname.new(source).relative_path_from(Pathname.new(File.dirname(target)))
|
||||
FileUtils.ln_sf(rel_path, target)
|
||||
end
|
||||
|
||||
puts 'Symlinks created successfully.'
|
||||
puts 'You can now run the Mintlify dev server to preview the documentation.'
|
||||
end
|
||||
end
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user