@@ -13,7 +13,7 @@ internal sealed class ResourceFieldSchemaBuilder
1313 private readonly SchemaGenerator _defaultSchemaGenerator ;
1414 private readonly ResourceIdentifierSchemaGenerator _resourceIdentifierSchemaGenerator ;
1515 private readonly LinksVisibilitySchemaGenerator _linksVisibilitySchemaGenerator ;
16- private readonly ResourceTypeInfo _resourceTypeInfo ;
16+ private readonly ResourceSchemaType _resourceSchemaType ;
1717 private readonly ResourceFieldValidationMetadataProvider _resourceFieldValidationMetadataProvider ;
1818 private readonly RelationshipTypeFactory _relationshipTypeFactory ;
1919
@@ -23,19 +23,19 @@ internal sealed class ResourceFieldSchemaBuilder
2323
2424 public ResourceFieldSchemaBuilder ( SchemaGenerator defaultSchemaGenerator , ResourceIdentifierSchemaGenerator resourceIdentifierSchemaGenerator ,
2525 LinksVisibilitySchemaGenerator linksVisibilitySchemaGenerator , ResourceFieldValidationMetadataProvider resourceFieldValidationMetadataProvider ,
26- RelationshipTypeFactory relationshipTypeFactory , ResourceTypeInfo resourceTypeInfo )
26+ RelationshipTypeFactory relationshipTypeFactory , ResourceSchemaType resourceSchemaType )
2727 {
2828 ArgumentGuard . NotNull ( defaultSchemaGenerator ) ;
2929 ArgumentGuard . NotNull ( resourceIdentifierSchemaGenerator ) ;
3030 ArgumentGuard . NotNull ( linksVisibilitySchemaGenerator ) ;
31- ArgumentGuard . NotNull ( resourceTypeInfo ) ;
31+ ArgumentGuard . NotNull ( resourceSchemaType ) ;
3232 ArgumentGuard . NotNull ( resourceFieldValidationMetadataProvider ) ;
3333 ArgumentGuard . NotNull ( relationshipTypeFactory ) ;
3434
3535 _defaultSchemaGenerator = defaultSchemaGenerator ;
3636 _resourceIdentifierSchemaGenerator = resourceIdentifierSchemaGenerator ;
3737 _linksVisibilitySchemaGenerator = linksVisibilitySchemaGenerator ;
38- _resourceTypeInfo = resourceTypeInfo ;
38+ _resourceSchemaType = resourceSchemaType ;
3939 _resourceFieldValidationMetadataProvider = resourceFieldValidationMetadataProvider ;
4040 _relationshipTypeFactory = relationshipTypeFactory ;
4141
@@ -44,9 +44,9 @@ public ResourceFieldSchemaBuilder(SchemaGenerator defaultSchemaGenerator, Resour
4444
4545 private IDictionary < string , OpenApiSchema > GetFieldSchemas ( )
4646 {
47- if ( ! _resourceSchemaRepository . TryLookupByType ( _resourceTypeInfo . ResourceType . ClrType , out OpenApiSchema referenceSchemaForResource ) )
47+ if ( ! _resourceSchemaRepository . TryLookupByType ( _resourceSchemaType . ResourceType . ClrType , out OpenApiSchema referenceSchemaForResource ) )
4848 {
49- referenceSchemaForResource = _defaultSchemaGenerator . GenerateSchema ( _resourceTypeInfo . ResourceType . ClrType , _resourceSchemaRepository ) ;
49+ referenceSchemaForResource = _defaultSchemaGenerator . GenerateSchema ( _resourceSchemaType . ResourceType . ClrType , _resourceSchemaRepository ) ;
5050 }
5151
5252 OpenApiSchema fullSchemaForResource = _resourceSchemaRepository . Schemas [ referenceSchemaForResource . Reference . Id ] ;
@@ -57,12 +57,13 @@ public void SetMembersOfAttributes(OpenApiSchema fullSchemaForAttributes, bool f
5757 {
5858 ArgumentGuard . NotNull ( fullSchemaForAttributes ) ;
5959 ArgumentGuard . NotNull ( schemaRepository ) ;
60+ AssertHasNoProperties ( fullSchemaForAttributes ) ;
6061
61- AttrCapabilities requiredCapability = GetRequiredCapabilityForAttributes ( _resourceTypeInfo . ResourceDataOpenType ) ;
62+ AttrCapabilities requiredCapability = GetRequiredCapabilityForAttributes ( _resourceSchemaType . SchemaOpenType ) ;
6263
63- foreach ( ( string fieldName , OpenApiSchema resourceFieldSchema ) in _schemasForResourceFields )
64+ foreach ( ( string publicName , OpenApiSchema schemaForResourceField ) in _schemasForResourceFields )
6465 {
65- AttrAttribute ? matchingAttribute = _resourceTypeInfo . ResourceType . FindAttributeByPublicName ( fieldName ) ;
66+ AttrAttribute ? matchingAttribute = _resourceSchemaType . ResourceType . FindAttributeByPublicName ( publicName ) ;
6667
6768 if ( matchingAttribute != null && matchingAttribute . Capabilities . HasFlag ( requiredCapability ) )
6869 {
@@ -81,24 +82,25 @@ public void SetMembersOfAttributes(OpenApiSchema fullSchemaForAttributes, bool f
8182 }
8283 }
8384
84- bool isInlineSchemaType = resourceFieldSchema . AllOf . Count == 0 ;
85+ bool isInlineSchemaType = schemaForResourceField . AllOf . Count == 0 ;
8586
8687 // Schemas for types like enum and complex attributes are handled as reference schemas.
8788 if ( ! isInlineSchemaType )
8889 {
89- EnsureAttributeSchemaIsExposed ( resourceFieldSchema . UnwrapLastExtendedSchema ( ) , matchingAttribute , schemaRepository ) ;
90+ OpenApiSchema referenceSchemaForAttribute = schemaForResourceField . UnwrapLastExtendedSchema ( ) ;
91+ EnsureAttributeSchemaIsExposed ( referenceSchemaForAttribute , matchingAttribute , schemaRepository ) ;
9092 }
9193
92- fullSchemaForAttributes . Properties . Add ( matchingAttribute . PublicName , resourceFieldSchema ) ;
94+ fullSchemaForAttributes . Properties . Add ( matchingAttribute . PublicName , schemaForResourceField ) ;
9395
94- resourceFieldSchema . Nullable = _resourceFieldValidationMetadataProvider . IsNullable ( matchingAttribute ) ;
96+ schemaForResourceField . Nullable = _resourceFieldValidationMetadataProvider . IsNullable ( matchingAttribute ) ;
9597
9698 if ( IsFieldRequired ( matchingAttribute ) )
9799 {
98100 fullSchemaForAttributes . Required . Add ( matchingAttribute . PublicName ) ;
99101 }
100102
101- resourceFieldSchema . Description = _resourceDocumentationReader . GetDocumentationForAttribute ( matchingAttribute ) ;
103+ schemaForResourceField . Description = _resourceDocumentationReader . GetDocumentationForAttribute ( matchingAttribute ) ;
102104 }
103105 }
104106 }
@@ -142,18 +144,19 @@ private Type GetRepresentedTypeForAttributeSchema(AttrAttribute attribute)
142144
143145 private bool IsFieldRequired ( ResourceFieldAttribute field )
144146 {
145- bool isCreateResourceSchemaType = _resourceTypeInfo . ResourceDataOpenType == typeof ( DataInCreateResourceRequest < > ) ;
147+ bool isCreateResourceSchemaType = _resourceSchemaType . SchemaOpenType == typeof ( DataInCreateResourceRequest < > ) ;
146148 return isCreateResourceSchemaType && _resourceFieldValidationMetadataProvider . IsRequired ( field ) ;
147149 }
148150
149151 public void SetMembersOfRelationships ( OpenApiSchema fullSchemaForRelationships , bool forRequestSchema , SchemaRepository schemaRepository )
150152 {
151153 ArgumentGuard . NotNull ( fullSchemaForRelationships ) ;
152154 ArgumentGuard . NotNull ( schemaRepository ) ;
155+ AssertHasNoProperties ( fullSchemaForRelationships ) ;
153156
154- foreach ( string fieldName in _schemasForResourceFields . Keys )
157+ foreach ( string publicName in _schemasForResourceFields . Keys )
155158 {
156- RelationshipAttribute ? matchingRelationship = _resourceTypeInfo . ResourceType . FindRelationshipByPublicName ( fieldName ) ;
159+ RelationshipAttribute ? matchingRelationship = _resourceSchemaType . ResourceType . FindRelationshipByPublicName ( publicName ) ;
157160
158161 if ( matchingRelationship != null )
159162 {
@@ -166,7 +169,7 @@ public void SetMembersOfRelationships(OpenApiSchema fullSchemaForRelationships,
166169 private void AddRelationshipSchemaToResourceData ( RelationshipAttribute relationship , OpenApiSchema fullSchemaForRelationships ,
167170 SchemaRepository schemaRepository )
168171 {
169- Type relationshipSchemaType = GetRelationshipSchemaType ( relationship , _resourceTypeInfo . ResourceDataOpenType ) ;
172+ Type relationshipSchemaType = GetRelationshipSchemaType ( relationship , _resourceSchemaType . SchemaOpenType ) ;
170173
171174 OpenApiSchema referenceSchemaForRelationship = GetReferenceSchemaForRelationship ( relationshipSchemaType , schemaRepository ) ??
172175 CreateReferenceSchemaForRelationship ( relationshipSchemaType , schemaRepository ) ;
@@ -182,9 +185,9 @@ private void AddRelationshipSchemaToResourceData(RelationshipAttribute relations
182185 }
183186 }
184187
185- private Type GetRelationshipSchemaType ( RelationshipAttribute relationship , Type resourceDataConstructedType )
188+ private Type GetRelationshipSchemaType ( RelationshipAttribute relationship , Type openSchemaType )
186189 {
187- bool isResponseSchemaType = resourceDataConstructedType . ConstructedToOpenType ( ) . IsAssignableTo ( typeof ( ResourceDataInResponse < > ) ) ;
190+ bool isResponseSchemaType = openSchemaType . IsAssignableTo ( typeof ( ResourceDataInResponse < > ) ) ;
188191 return isResponseSchemaType ? _relationshipTypeFactory . GetForResponse ( relationship ) : _relationshipTypeFactory . GetForRequest ( relationship ) ;
189192 }
190193
@@ -211,4 +214,12 @@ private OpenApiSchema CreateReferenceSchemaForRelationship(Type relationshipSche
211214
212215 return referenceSchema ;
213216 }
217+
218+ private static void AssertHasNoProperties ( OpenApiSchema fullSchema )
219+ {
220+ if ( fullSchema . Properties . Count > 0 )
221+ {
222+ throw new UnreachableCodeException ( ) ;
223+ }
224+ }
214225}
0 commit comments