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: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
admin-spec:
./plugins convert_json_schema --plugins $$(ls schemas/) --version 3.10.x --skip-custom-annotations; cp -r json_schemas/* ../kong-admin-spec-generator/data/plugins
39 changes: 24 additions & 15 deletions lib/convert_json_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def run!

# Fix any broken defaults
json_schema = fix_broken_defaults(json_schema)
json_schema = fix_regex(json_schema)

# Write the schema to the destination
FileUtils.mkdir_p("#{@options[:destination]}/#{plugin_name}")
Expand Down Expand Up @@ -85,21 +86,24 @@ def convert_to_json_schema(props)
fields['format'] = 'uuid'
end

if k == 'encrypted'
note = 'This field is [encrypted](/gateway/keyring/).'
if fields.key?('description')
fields['description'] << "\n#{note}"
else
fields['description'] = note

if !@options[:skip_custom_annotations]
if k == 'encrypted'
note = 'This field is [encrypted](/gateway/keyring/).'
if fields.key?('description')
fields['description'] << "\n#{note}"
else
fields['description'] = note
end
end
end

if k == 'referenceable'
note = 'This field is [referenceable](/gateway/entities/vault/#how-do-i-reference-secrets-stored-in-a-vault).'
if fields.key?('description')
fields['description'] << "\n#{note}"
else
fields['description'] = note
if k == 'referenceable'
note = 'This field is [referenceable](/gateway/entities/vault/#how-do-i-reference-secrets-stored-in-a-vault).'
if fields.key?('description')
fields['description'] << "\n#{note}"
else
fields['description'] = note
end
end
end

Expand Down Expand Up @@ -182,7 +186,7 @@ def convert_required_list(schema)
end

end


schema
end
Expand Down Expand Up @@ -232,6 +236,7 @@ def fix_regex(schema)
# Escape forward slashes
schema['pattern'] = schema['pattern'].gsub('%/', '\\/')
end

if schema['items']
schema['items'] = fix_regex(schema['items'])
end
Expand All @@ -251,10 +256,14 @@ def fix_broken_defaults(schema)
if schema['properties']
schema['properties'].each do |k, v|
schema['properties'][k] = fix_broken_defaults(v)
schema['properties'][k] = fix_regex(v)
schema['properties'][k] = fix_regex(schema['properties'][k])
end
end

if schema['items']
schema['items'] = fix_broken_defaults(schema['items'])
end

return schema
end

Expand Down