Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generates unique DELETE operation ids of $ref paths for indexed collection navigation properties #513

Merged
merged 5 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,13 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageId>Microsoft.OpenApi.OData</PackageId>
<SignAssembly>true</SignAssembly>
<Version>1.6.0</Version>
<Version>1.6.1</Version>
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET.OData</RepositoryUrl>
<PackageReleaseNotes>
- Reads annotations on structural properties of stream types for media entity paths #399
- Updates the format of the request body schema of a collection of complex property #423
- Adds a delete operation and a required @id query parameter to collection-valued navigation property paths with $ref #453
- Fixes inconsistency of nullability of schemas of properties that are a collection of structured types #467
- Generates $expand query parameter for operations whose return type is a collection #481
- Adds delete operation for non-contained navigation properties only if explicitly allowed via annotation #483
- Appends parameters and fixes operation ids of navigation property paths generated via composable functions #486
- Use alternate keys in the generation of operation ids of operations and navigation property alternate paths #488
- Fixes operation ids of paths with type cast segments #492
- Uses convert setting to toggle between generating query options schemas of type string array or enums #197
- Adds ability to change the response or request body content media type based on custom annotation properties #405
- Generates unique DELETE operation ids of $ref paths for indexed collection navigation properties #513
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ internal abstract class NavigationPropertyOperationHandler : OperationHandler
/// <summary>
/// Gets a bool value indicating whether the last segment is a key segment.
/// </summary>
protected bool LastSegmentIsKeySegment { get; private set; }
protected bool LastSegmentIsKeySegment { get; private set; }

/// <summary>
/// Gets a bool value indicating whether the second last segment in a $ref path is a key segment
/// </summary>
protected bool SecondLastSegmentIsKeySegment { get; private set; }

/// <summary>
/// Gets a bool value indicating whether the last segment is a $ref segment.
Expand All @@ -55,7 +60,8 @@ protected override void Initialize(ODataContext context, ODataPath path)
NavigationSource = navigationSourceSegment.NavigationSource;

LastSegmentIsKeySegment = path.LastSegment is ODataKeySegment;
LastSegmentIsRefSegment = path.LastSegment is ODataRefSegment;
LastSegmentIsRefSegment = path.LastSegment is ODataRefSegment;
SecondLastSegmentIsKeySegment = Path.Segments.Reverse().Skip(1).Take(1).Single().Kind == ODataSegmentKind.Key;
baywet marked this conversation as resolved.
Show resolved Hide resolved
NavigationProperty = path.OfType<ODataNavigationPropertySegment>().Last().NavigationProperty;

IEdmEntitySet entitySet = NavigationSource as IEdmEntitySet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------

using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Generator;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
using System.Linq;

namespace Microsoft.OpenApi.OData.Operation
{
Expand Down Expand Up @@ -40,8 +40,22 @@ protected override void SetBasicInfo(OpenApiOperation operation)
// OperationId
if (Context.Settings.EnableOperationId)
{
string prefix = "DeleteRef";
operation.OperationId = GetOperationId(prefix);
string prefix = "DeleteRef";
var segments = GetOperationId().Split('.').ToList();
baywet marked this conversation as resolved.
Show resolved Hide resolved

if (SecondLastSegmentIsKeySegment)
{
segments[segments.Count - 1] = Utils.ToFirstCharacterLowerCase(segments[segments.Count - 1]);
var lastSegment = prefix + Utils.UpperFirstChar(NavigationProperty.ToEntityType().Name);
segments.Add(lastSegment);
operation.OperationId = string.Join(".", segments);
}
else
{
var lastSegment = segments.LastOrDefault();
segments[segments.Count - 1] = prefix + lastSegment;
operation.OperationId = string.Join(".", segments);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@
"Documents.RevisionDto"
],
"summary": "Delete ref of navigation property Revisions for Documents",
"operationId": "Documents.DeleteRefRevisions",
"operationId": "Documents.revisions.DeleteRefRevisionDto",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -1673,7 +1673,7 @@
"Libraries.DocumentDto"
],
"summary": "Delete ref of navigation property Documents for Libraries",
"operationId": "Libraries.DeleteRefDocuments",
"operationId": "Libraries.documents.DeleteRefDocumentDto",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -3688,7 +3688,7 @@
"Tasks.RevisionDto"
],
"summary": "Delete ref of navigation property Revisions for Tasks",
"operationId": "Tasks.DeleteRefRevisions",
"operationId": "Tasks.revisions.DeleteRefRevisionDto",
"parameters": [
{
"in": "path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ paths:
tags:
- Documents.RevisionDto
summary: Delete ref of navigation property Revisions for Documents
operationId: Documents.DeleteRefRevisions
operationId: Documents.revisions.DeleteRefRevisionDto
parameters:
- in: path
name: Id
Expand Down Expand Up @@ -1185,7 +1185,7 @@ paths:
tags:
- Libraries.DocumentDto
summary: Delete ref of navigation property Documents for Libraries
operationId: Libraries.DeleteRefDocuments
operationId: Libraries.documents.DeleteRefDocumentDto
parameters:
- in: path
name: Id
Expand Down Expand Up @@ -2623,7 +2623,7 @@ paths:
tags:
- Tasks.RevisionDto
summary: Delete ref of navigation property Revisions for Tasks
operationId: Tasks.DeleteRefRevisions
operationId: Tasks.revisions.DeleteRefRevisionDto
parameters:
- in: path
name: Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@
"Documents.RevisionDto"
],
"summary": "Delete ref of navigation property Revisions for Documents",
"operationId": "Documents.DeleteRefRevisions",
"operationId": "Documents.revisions.DeleteRefRevisionDto",
"parameters": [
{
"name": "Id",
Expand Down Expand Up @@ -1863,7 +1863,7 @@
"Libraries.DocumentDto"
],
"summary": "Delete ref of navigation property Documents for Libraries",
"operationId": "Libraries.DeleteRefDocuments",
"operationId": "Libraries.documents.DeleteRefDocumentDto",
"parameters": [
{
"name": "Id",
Expand Down Expand Up @@ -4128,7 +4128,7 @@
"Tasks.RevisionDto"
],
"summary": "Delete ref of navigation property Revisions for Tasks",
"operationId": "Tasks.DeleteRefRevisions",
"operationId": "Tasks.revisions.DeleteRefRevisionDto",
"parameters": [
{
"name": "Id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ paths:
tags:
- Documents.RevisionDto
summary: Delete ref of navigation property Revisions for Documents
operationId: Documents.DeleteRefRevisions
operationId: Documents.revisions.DeleteRefRevisionDto
parameters:
- name: Id
in: path
Expand Down Expand Up @@ -1312,7 +1312,7 @@ paths:
tags:
- Libraries.DocumentDto
summary: Delete ref of navigation property Documents for Libraries
operationId: Libraries.DeleteRefDocuments
operationId: Libraries.documents.DeleteRefDocumentDto
parameters:
- name: Id
in: path
Expand Down Expand Up @@ -2913,7 +2913,7 @@ paths:
tags:
- Tasks.RevisionDto
summary: Delete ref of navigation property Revisions for Tasks
operationId: Tasks.DeleteRefRevisions
operationId: Tasks.revisions.DeleteRefRevisionDto
parameters:
- name: Id
in: path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2238,7 +2238,7 @@
"Me.Person"
],
"summary": "Delete ref of navigation property Friends for Me",
"operationId": "Me.DeleteRefFriends",
"operationId": "Me.friends.DeleteRefPerson",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -4261,7 +4261,7 @@
"Me.Person"
],
"summary": "Delete ref of navigation property Friends for Me",
"operationId": "Me.AsEmployee.DeleteRefFriends",
"operationId": "Me.AsEmployee.friends.DeleteRefPerson",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -5228,7 +5228,7 @@
"Me.Person"
],
"summary": "Delete ref of navigation property Peers for Me",
"operationId": "Me.AsEmployee.DeleteRefPeers",
"operationId": "Me.AsEmployee.peers.DeleteRefPerson",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -6329,7 +6329,7 @@
"Me.Trips.PlanItem"
],
"summary": "Delete ref of navigation property PlanItems for Me",
"operationId": "Me.AsEmployee.Trips.DeleteRefPlanItems",
"operationId": "Me.AsEmployee.Trips.planItems.DeleteRefPlanItem",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -7768,7 +7768,7 @@
"Me.Person"
],
"summary": "Delete ref of navigation property DirectReports for Me",
"operationId": "Me.AsManager.DeleteRefDirectReports",
"operationId": "Me.AsManager.directReports.DeleteRefPerson",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -8491,7 +8491,7 @@
"Me.Person"
],
"summary": "Delete ref of navigation property Friends for Me",
"operationId": "Me.AsManager.DeleteRefFriends",
"operationId": "Me.AsManager.friends.DeleteRefPerson",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -9910,7 +9910,7 @@
"Me.Trips.PlanItem"
],
"summary": "Delete ref of navigation property PlanItems for Me",
"operationId": "Me.AsManager.Trips.DeleteRefPlanItems",
"operationId": "Me.AsManager.Trips.planItems.DeleteRefPlanItem",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -10749,7 +10749,7 @@
"Me.Trips.PlanItem"
],
"summary": "Delete ref of navigation property PlanItems for Me",
"operationId": "Me.Trips.DeleteRefPlanItems",
"operationId": "Me.Trips.planItems.DeleteRefPlanItem",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -12414,7 +12414,7 @@
"NewComePeople.Person"
],
"summary": "Delete ref of navigation property Friends for NewComePeople",
"operationId": "NewComePeople.DeleteRefFriends",
"operationId": "NewComePeople.friends.DeleteRefPerson",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -14250,7 +14250,7 @@
"NewComePeople.Trips.PlanItem"
],
"summary": "Delete ref of navigation property PlanItems for NewComePeople",
"operationId": "NewComePeople.Trips.DeleteRefPlanItems",
"operationId": "NewComePeople.Trips.planItems.DeleteRefPlanItem",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -16015,7 +16015,7 @@
"People.Person"
],
"summary": "Delete ref of navigation property Friends for People",
"operationId": "People.DeleteRefFriends",
"operationId": "People.friends.DeleteRefPerson",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -18428,7 +18428,7 @@
"People.Person"
],
"summary": "Delete ref of navigation property Friends for People",
"operationId": "People.AsEmployee.DeleteRefFriends",
"operationId": "People.AsEmployee.friends.DeleteRefPerson",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -19565,7 +19565,7 @@
"People.Person"
],
"summary": "Delete ref of navigation property Peers for People",
"operationId": "People.AsEmployee.DeleteRefPeers",
"operationId": "People.AsEmployee.peers.DeleteRefPerson",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -20834,7 +20834,7 @@
"People.Trips.PlanItem"
],
"summary": "Delete ref of navigation property PlanItems for People",
"operationId": "People.AsEmployee.Trips.DeleteRefPlanItems",
"operationId": "People.AsEmployee.Trips.planItems.DeleteRefPlanItem",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -22551,7 +22551,7 @@
"People.Person"
],
"summary": "Delete ref of navigation property DirectReports for People",
"operationId": "People.AsManager.DeleteRefDirectReports",
"operationId": "People.AsManager.directReports.DeleteRefPerson",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -23394,7 +23394,7 @@
"People.Person"
],
"summary": "Delete ref of navigation property Friends for People",
"operationId": "People.AsManager.DeleteRefFriends",
"operationId": "People.AsManager.friends.DeleteRefPerson",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -25039,7 +25039,7 @@
"People.Trips.PlanItem"
],
"summary": "Delete ref of navigation property PlanItems for People",
"operationId": "People.AsManager.Trips.DeleteRefPlanItems",
"operationId": "People.AsManager.Trips.planItems.DeleteRefPlanItem",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -25998,7 +25998,7 @@
"People.Trips.PlanItem"
],
"summary": "Delete ref of navigation property PlanItems for People",
"operationId": "People.Trips.DeleteRefPlanItems",
"operationId": "People.Trips.planItems.DeleteRefPlanItem",
"parameters": [
{
"in": "path",
Expand Down
Loading
Loading