From b9fb735d14407c8be7b585bec68f3d58cadc05ec Mon Sep 17 00:00:00 2001 From: Alex Woods Date: Wed, 28 Aug 2024 13:14:15 -0700 Subject: [PATCH 1/2] Ignore unknown metadata and shape keys --- .../lib/aws-sdk-code-generator/service.rb | 25 +++++++++++++++++++ .../views/client_api_module.rb | 4 +-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/service.rb b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/service.rb index 334e3b5a9ee..f96c03851f0 100644 --- a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/service.rb +++ b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/service.rb @@ -192,6 +192,31 @@ def deprecated? @deprecated end + # @return list of validation messages + def validate + errors = [] + @api.fetch('metadata', {}).keys.sort.each do |key| + if AwsSdkCodeGenerator::Views::ClientApiModule::METADATA_KEYS[key].nil? + errors << { + type: :invalid_key, + message: "invalid/unsupported metadata key `#{key}`" + } + end + end + + @api.fetch('shapes', {}).each do |shape_name, shape| + shape.each_pair do |key, _| + unless AwsSdkCodeGenerator::Views::ClientApiModule::SHAPE_KEYS.key?(key) + errors << { + type: :invalid_key, + message: "invalid/unsupported shape key `#{key}` on `#{shape_name}`" + } + end + end + end + errors + end + # @api private def inspect "#<#{self.class.name}>" diff --git a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/client_api_module.rb b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/client_api_module.rb index 452fd4c0924..5a838a41b48 100644 --- a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/client_api_module.rb +++ b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/client_api_module.rb @@ -192,7 +192,7 @@ def metadata value: @service.api['metadata'][key].inspect } elsif METADATA_KEYS[key].nil? - raise "unhandled metadata key #{key.inspect}" + warn "unhandled metadata key #{key.inspect}" end end metadata @@ -317,7 +317,7 @@ def shape_constructor_args(shape_name, shape) args << "#{key}: #{value.inspect}" elsif SHAPE_KEYS[key].nil? - raise "unhandled shape key #{key.inspect}" + warn "unhandled shape key #{key.inspect}" end end args.join(', ') From 1ed43b799ead2f4f355a7c89445fb734af3f7dd6 Mon Sep 17 00:00:00 2001 From: Alex Woods Date: Thu, 29 Aug 2024 09:27:50 -0700 Subject: [PATCH 2/2] Move validation into code generation --- .../lib/aws-sdk-code-generator.rb | 9 +++++++ .../lib/aws-sdk-code-generator/service.rb | 25 ------------------- .../views/client_api_module.rb | 12 +++++++-- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator.rb b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator.rb index 49425146ebe..139a6d34548 100644 --- a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator.rb +++ b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator.rb @@ -103,4 +103,13 @@ module AwsSdkCodeGenerator # WARNING ABOUT GENERATED CODE WARNING_TXT + @warnings = [] + + class << self + attr_reader :warnings + def warn(service, type, message) + Kernel.warn(message) + @warnings << { service: service, type: type, message: message } + end + end end diff --git a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/service.rb b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/service.rb index f96c03851f0..334e3b5a9ee 100644 --- a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/service.rb +++ b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/service.rb @@ -192,31 +192,6 @@ def deprecated? @deprecated end - # @return list of validation messages - def validate - errors = [] - @api.fetch('metadata', {}).keys.sort.each do |key| - if AwsSdkCodeGenerator::Views::ClientApiModule::METADATA_KEYS[key].nil? - errors << { - type: :invalid_key, - message: "invalid/unsupported metadata key `#{key}`" - } - end - end - - @api.fetch('shapes', {}).each do |shape_name, shape| - shape.each_pair do |key, _| - unless AwsSdkCodeGenerator::Views::ClientApiModule::SHAPE_KEYS.key?(key) - errors << { - type: :invalid_key, - message: "invalid/unsupported shape key `#{key}` on `#{shape_name}`" - } - end - end - end - errors - end - # @api private def inspect "#<#{self.class.name}>" diff --git a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/client_api_module.rb b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/client_api_module.rb index 5a838a41b48..fed3e51e3c6 100644 --- a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/client_api_module.rb +++ b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/client_api_module.rb @@ -192,7 +192,11 @@ def metadata value: @service.api['metadata'][key].inspect } elsif METADATA_KEYS[key].nil? - warn "unhandled metadata key #{key.inspect}" + AwsSdkCodeGenerator.warn( + @service.service_id, + :invalid_key, + "unhandled metadata key `#{key}`" + ) end end metadata @@ -317,7 +321,11 @@ def shape_constructor_args(shape_name, shape) args << "#{key}: #{value.inspect}" elsif SHAPE_KEYS[key].nil? - warn "unhandled shape key #{key.inspect}" + AwsSdkCodeGenerator.warn( + @service.service_id, + :invalid_key, + "unhandled shape key `#{key}` on `#{shape_name}`" + ) end end args.join(', ')