Skip to content

Commit fab05c8

Browse files
committed
Fixed: do not generate duplicate operation ID when secondary resource type is same as primary resource type at secondary endpoint
1 parent 55ee6f4 commit fab05c8

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/JsonApiDotNetCore.OpenApi/JsonApiOperationIdSelector.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ public string GetOperationId(ApiDescription endpoint)
5656
throw new UnreachableCodeException();
5757
}
5858

59-
string template = GetTemplate(primaryResourceType.ClrType, endpoint);
59+
string template = GetTemplate(endpoint);
6060

6161
return ApplyTemplate(template, primaryResourceType, endpoint);
6262
}
6363

64-
private static string GetTemplate(Type resourceClrType, ApiDescription endpoint)
64+
private static string GetTemplate(ApiDescription endpoint)
6565
{
66-
Type requestDocumentType = GetDocumentType(resourceClrType, endpoint);
66+
Type requestDocumentType = GetDocumentType(endpoint);
6767

6868
if (!DocumentOpenTypeToOperationIdTemplateMap.TryGetValue(requestDocumentType, out string? template))
6969
{
@@ -73,7 +73,7 @@ private static string GetTemplate(Type resourceClrType, ApiDescription endpoint)
7373
return template;
7474
}
7575

76-
private static Type GetDocumentType(Type primaryResourceClrType, ApiDescription endpoint)
76+
private static Type GetDocumentType(ApiDescription endpoint)
7777
{
7878
var producesResponseTypeAttribute = endpoint.ActionDescriptor.GetFilterMetadata<ProducesResponseTypeAttribute>();
7979

@@ -87,14 +87,9 @@ private static Type GetDocumentType(Type primaryResourceClrType, ApiDescription
8787
Type documentType = requestBodyDescriptor?.ParameterType.GetGenericTypeDefinition() ??
8888
GetGenericTypeDefinition(producesResponseTypeAttribute.Type) ?? producesResponseTypeAttribute.Type;
8989

90-
if (documentType == typeof(ResourceCollectionResponseDocument<>))
90+
if (documentType == typeof(ResourceCollectionResponseDocument<>) && endpoint.ParameterDescriptions.Count > 0)
9191
{
92-
Type documentResourceType = producesResponseTypeAttribute.Type.GetGenericArguments()[0];
93-
94-
if (documentResourceType != primaryResourceClrType)
95-
{
96-
documentType = typeof(SecondaryResourceResponseDocument<>);
97-
}
92+
documentType = typeof(SecondaryResourceResponseDocument<>);
9893
}
9994

10095
return documentType;

0 commit comments

Comments
 (0)