From aaa9974ee309a27b7d779b2dee5c4a839f514027 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Thu, 24 Apr 2025 10:43:26 +0100 Subject: [PATCH 1/2] Add --skip-custom-annotations flag --- Makefile | 2 ++ lib/convert_json_schema.rb | 31 +++++++++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..4bf1b310 --- /dev/null +++ b/Makefile @@ -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 \ No newline at end of file diff --git a/lib/convert_json_schema.rb b/lib/convert_json_schema.rb index 562328b5..f42dbf6b 100644 --- a/lib/convert_json_schema.rb +++ b/lib/convert_json_schema.rb @@ -85,21 +85,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 @@ -182,7 +185,7 @@ def convert_required_list(schema) end end - + schema end From 7541f1352d329748a9f37bff85d3bd6ea1f17bb7 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Thu, 24 Apr 2025 10:59:37 +0100 Subject: [PATCH 2/2] Fix regex replacement --- lib/convert_json_schema.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/convert_json_schema.rb b/lib/convert_json_schema.rb index f42dbf6b..d28a17db 100644 --- a/lib/convert_json_schema.rb +++ b/lib/convert_json_schema.rb @@ -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}") @@ -235,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 @@ -254,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