Commit 2458af6

mo khan <mo@mokhan.ca>
2026-08-04 02:19:05
fix: stop requiring attributes RFC 7643 leaves optional
Section 3.1 marks no meta sub-attribute REQUIRED, and section 6 makes id OPTIONAL for ResourceType. Both were reported as non-conformance.
cli
1 parent 4122023
Changed files (3)
lib/scim/kit/cli/resource_schema_resolver.rb
@@ -20,13 +20,18 @@ module Scim
               },
               'location' => { 'type' => 'string' },
               'version' => { 'type' => 'string' }
-            },
-            'required' => ['resourceType']
+            }
           }
         }.freeze
 
         COMMON_REQUIRED = %w[schemas id].freeze
 
+        # RFC 7643 6 makes "id" OPTIONAL for these discovery resources.
+        OPTIONAL_ID_SCHEMAS = [
+          'urn:ietf:params:scim:schemas:core:2.0:ResourceType',
+          'urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig'
+        ].freeze
+
         attr_reader :undeclared_extensions
 
         def initialize(client)
@@ -61,17 +66,24 @@ module Scim
           merge_extensions(
             resource_type, schemas, properties, required
           )
-          build_schema(properties, required)
+          build_schema(properties, common_required(resource_type) | required)
         end
 
         def build_schema(properties, required)
           {
             'type' => 'object',
             'properties' => properties,
-            'required' => COMMON_REQUIRED | required
+            'required' => required
           }
         end
 
+        def common_required(resource_type)
+          return COMMON_REQUIRED unless
+            OPTIONAL_ID_SCHEMAS.include?(resource_type[:schema])
+
+          COMMON_REQUIRED - ['id']
+        end
+
         def merge_extensions(resource_type, schemas, properties, required)
           Array(resource_type[:schemaExtensions]).each do |extension|
             extension_schema = schemas[extension[:schema]]
spec/scim/kit/cli/resource_schema_resolver_spec.rb
@@ -95,9 +95,38 @@ RSpec.describe Scim::Kit::Cli::ResourceSchemaResolver do
           .to include(/missing required keys.*id/)
       end
 
-      it 'requires meta.resourceType when meta is returned' do
-        expect(errors_for(resource.merge(meta: {})))
-          .to include(/meta.*missing required keys.*resourceType/)
+      it 'accepts a partial meta, which RFC 7643 3.1 leaves optional' do
+        expect(errors_for(resource.merge(meta: { location: '/Users/1' })))
+          .to be_empty
+      end
+    end
+
+    context 'when the resource type is ResourceType' do
+      let(:resource_type_urn) do
+        'urn:ietf:params:scim:schemas:core:2.0:ResourceType'
+      end
+      let(:resource_type) do
+        {
+          id: 'ResourceType', name: 'ResourceType',
+          endpoint: '/ResourceTypes', schema: resource_type_urn
+        }
+      end
+      let(:core_schema) do
+        {
+          id: resource_type_urn,
+          attributes: [{ name: 'name', type: 'string', required: true }]
+        }
+      end
+
+      before do
+        stub_request(:get, "#{base_url}/Schemas")
+          .to_return(status: 200, body: [core_schema].to_json)
+      end
+
+      it 'does not require id, which RFC 7643 6 leaves optional' do
+        errors = errors_for(schemas: [resource_type_urn], name: 'User')
+
+        expect(errors).to be_empty
       end
     end
 
README.md
@@ -116,11 +116,13 @@ scim-kit list User --validate
 and `get` build a schema from the target server's *own* `/Schemas` document,
 so they check that a server's resources match the schema it advertises.
 
-Validation enforces what RFC 7643 §3.1 requires of a returned resource — the
-`schemas` and `id` attributes, and `meta.resourceType` when `meta` is present
-— along with the types, canonical values, and required attributes the server
-declares. Undeclared vendor properties are permitted, and `--attributes`
-relaxes the required checks so sparse responses are not reported as errors.
+Validation enforces what RFC 7643 §3.1 requires of a returned resource - the
+`schemas` and `id` attributes, except that `id` is optional on the
+`ResourceType` and `ServiceProviderConfig` resources per §6 - along with the
+types, canonical values, and required attributes the server declares. Every
+`meta` sub-attribute is optional. Undeclared vendor properties are permitted,
+and `--attributes` relaxes the required checks so sparse responses are not
+reported as errors.
 
 ## Development