Skip to content

Commit 4084e40

Browse files
committed
Merge branch 'main' into gh-2231
2 parents 876f292 + 8baff28 commit 4084e40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+433
-406
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ var document = new OpenApiDocument
5555
{
5656
["/pets"] = new OpenApiPathItem
5757
{
58-
Operations = new Dictionary<OperationType, OpenApiOperation>
58+
Operations = new Dictionary<HttpMethod, OpenApiOperation>
5959
{
60-
[OperationType.Get] = new OpenApiOperation
60+
[HttpMethod.Get] = new OpenApiOperation
6161
{
6262
Description = "Returns all pets from the system that the user has access to",
6363
Responses = new OpenApiResponses

src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Net.Http;
45
using System.Text;
56
using System.Text.RegularExpressions;
67
using Humanizer;
@@ -53,11 +54,11 @@ public override void Visit(IOpenApiSchema schema)
5354

5455
public override void Visit(IOpenApiPathItem pathItem)
5556
{
56-
if (pathItem.Operations.TryGetValue(OperationType.Put, out var value) &&
57+
if (pathItem.Operations.TryGetValue(HttpMethod.Put, out var value) &&
5758
value.OperationId != null)
5859
{
5960
var operationId = value.OperationId;
60-
pathItem.Operations[OperationType.Put].OperationId = ResolvePutOperationId(operationId);
61+
pathItem.Operations[HttpMethod.Put].OperationId = ResolvePutOperationId(operationId);
6162
}
6263

6364
base.Visit(pathItem);

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options,
256256
return document;
257257
}
258258

259-
private static Func<string, OperationType?, OpenApiOperation, bool>? FilterOpenApiDocument(string? filterByOperationIds, string? filterByTags, Dictionary<string, List<string>> requestUrls, OpenApiDocument document, ILogger logger)
259+
private static Func<string, HttpMethod, OpenApiOperation, bool>? FilterOpenApiDocument(string? filterByOperationIds, string? filterByTags, Dictionary<string, List<string>> requestUrls, OpenApiDocument document, ILogger logger)
260260
{
261-
Func<string, OperationType?, OpenApiOperation, bool>? predicate = null;
261+
Func<string, HttpMethod, OpenApiOperation, bool>? predicate = null;
262262

263263
using (logger.BeginScope("Create Filter"))
264264
{

src/Microsoft.OpenApi.Hidi/readme.md

Lines changed: 67 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,22 @@ Install [Microsoft.OpenApi.Hidi](https://www.nuget.org/packages/Microsoft.OpenAp
1717

1818
### .NET CLI(Global)
1919

20-
1. dotnet tool install --global Microsoft.OpenApi.Hidi --prerelease
21-
20+
```bash
21+
dotnet tool install --global Microsoft.OpenApi.Hidi --prerelease
22+
```
2223

2324
### .NET CLI(local)
24-
25-
1. dotnet new tool-manifest #if you are setting up the OpenAPI.NET repo
26-
2. dotnet tool install --local Microsoft.OpenApi.Hidi --prerelease
2725

26+
```bash
27+
dotnet new tool-manifest #if you are setting up the OpenAPI.NET repo
28+
dotnet tool install --local Microsoft.OpenApi.Hidi --prerelease
29+
```
2830

2931

3032

3133
## How to use Hidi
3234

33-
Once you've installed the package locally, you can invoke the Hidi by running: hidi [command].
34-
You can access the list of command options we have by running hidi -h
35+
Once you've installed the package locally, you can invoke the Hidi by running: `hidi [command]`. You can access the list of command options we have by running `hidi -h`
3536
The tool avails the following commands:
3637

3738
• Validate
@@ -57,63 +58,84 @@ It accepts the following command:
5758
• --loglevel(-ll) - The log level to use when logging messages to the main output
5859
5960

60-
**Example:** `hidi.exe validate --openapi C:\OpenApidocs\Mail.yml --loglevel trace`
61+
#### Example:
6162

62-
Run validate -h to see the options available.
63+
```bash
64+
hidi validate --openapi C:\OpenApidocs\Mail.yml --loglevel trace`
65+
```
66+
67+
> Run `hidi validate -h` to see the options available.
6368

6469
### Transform
6570

6671
Used to convert file formats from JSON to YAML and vice versa and performs slicing of OpenAPI documents.
6772

6873
This command accepts the following parameters:
6974

70-
• --openapi(-d) - OpenAPI description file path in the local filesystem or a valid URL hosted on a HTTPS server
71-
• --csdl(--cs) - CSDL file path in the local filesystem or a valid URL hosted on a HTTPS server
72-
• --csdlfilter(--csf) - a filter parameter that a user can use to select a subset of a large CSDL file. They do so by providing a comma delimited list of EntitySet and Singleton names that appear in the EntityContainer.
73-
• --output(-o) - Output directory path for the transformed document.
74-
• --output-folder(--of) - The output directory path for the generated files.
75-
• --clean-ouput(--co) - an optional param that allows a user to overwrite an existing file.
76-
• --version(-v) - OpenAPI specification version.
77-
• --metadata-version(--mv) - the metadata version to use.
78-
• --format(-f) - File format
79-
• --terse-output(--to) - Produce terse json output
80-
• --settings-path(--sp) - The configuration file with CSDL conversion settings.
81-
• --loglevel(--ll) - The log level to use when logging messages to the main output
82-
• --inline-local - Inline local $ref instances
83-
• --inline-external(--ex) - Inline external $refs
84-
• --filterByOperationIds(--op) - Slice document based on OperationId(s) provided. Accepts a comma delimited list of operation ids.
85-
• --filterByTags(-t) - Slice document based on tag(s) provided. Accepts a comma delimited list of tags.
86-
• --filterByCollection(-c) - Slices the OpenAPI document based on the Postman Collection file generated by Resource Explorer
87-
• --manifest (-m) - Slices the OpenAPI document based on the requests defined in the API Manifest file referenced by the provided URI. For API manifests with multiple API Dependenties, use a fragment identifier to select the desired one. e.g ./apimanifest.json#example
75+
76+
• --openapi, (-d) - OpenAPI description file path in the local filesystem or a valid URL hosted on a HTTPS server
77+
• --csdl (--cs) - CSDL file path in the local filesystem or a valid URL hosted on a HTTPS server
78+
• --csdl-filter (--csf) - a filter parameter that a user can use to select a subset of a large CSDL file. They do so by providing a comma delimited list of EntitySet and Singleton names that appear in the EntityContainer.
79+
• --output (-o) - Output directory path for the transformed document.
80+
• --clean-output (--co) - an optional param that allows a user to overwrite an existing file.
81+
• --version (-v) - OpenAPI specification version.
82+
• --metadata-version (--mv) - the metadata version to use.
83+
• --format (-f) - File format
84+
• --terse-output (--to) - Produce terse json output
85+
• --settings-path (--sp) - The configuration file with CSDL conversion settings.
86+
• --log-level (--ll) - The log level to use when logging messages to the main output
87+
• --inline-local (--il) - Inline local $ref instances
88+
• --inline-external (--ie) - Inline external $refs instances
89+
• --filter-by-operationids(--op) - Slice document based on OperationId(s) provided. Accepts a comma delimited list of operation ids.
90+
• --filter-by-tags (--t) - Slice document based on tag(s) provided. Accepts a comma delimited list of tags.
91+
• --filter-by-collection (-c) - Slices the OpenAPI document based on the Postman Collection file generated by Resource Explorer
8892

89-
**Examples:**
93+
#### Examples:
9094

91-
1. Filtering by OperationIds
92-
hidi transform -d files\People.yml -f yaml -o files\People.yml -v OpenApi3_0 --op users_UpdateInsights --co
93-
94-
2. Filtering by Postman collection
95-
hidi transform --openapi files\People.yml --format yaml --output files\People2.yml --version OpenApi3_0 --filterByCollection Graph-Collection-0017059134807617005.postman_collection.json
96-
97-
3. CSDL--->OpenAPI conversion and filtering
98-
hidi transform --csdl Files/Todo.xml --output Files/Todo-subset.yml --format yaml --version OpenApi3_0 --filterByOperationIds Todos.Todo.UpdateTodo
99-
100-
4. CSDL Filtering by EntitySets and Singletons
101-
hidi transform --cs dataverse.csdl --csdlFilter "appointments,opportunities" -o appointmentsAndOpportunities.yaml --ll trace
102-
103-
Run transform -h to see all the available usage options.
95+
1. Filtering by OperationIds
96+
97+
```bash
98+
hidi transform -d files\People.yml -f yaml -o files\People.yml -v OpenApi3_0 --op users_UpdateInsights --co
99+
```
100+
101+
2. Filtering by Postman collection
102+
103+
```bash
104+
hidi transform --openapi files\People.yml --format yaml --output files\People2.yml --version OpenApi3_0 --filter-by-collection Graph-Collection-0017059134807617005.postman_collection.json
105+
```
106+
107+
3. CSDL--->OpenAPI conversion and filtering
108+
109+
```bash
110+
hidi transform --csdl Files/Todo.xml --output Files/Todo-subset.yml --format yaml --version OpenApi3_0 --filter-by-operationids Todos.Todo.UpdateTodo
111+
```
112+
113+
4. CSDL Filtering by EntitySets and Singletons
114+
115+
```bash
116+
hidi transform --cs dataverse.csdl --csdl-filter "appointments,opportunities" -o appointmentsAndOpportunities.yaml --ll trace
117+
```
118+
119+
> Run `hidi transform -h` to see all the available usage options.
104120

105121
### Show
106122

107123
This command accepts an OpenAPI document as an input parameter and generates a Markdown file that contains a diagram of the API using Mermaid syntax.
108124

109-
**Examples:**
125+
#### Examples:
110126

111-
1. hidi show -d files\People.yml -o People.md -ll trace
127+
```bash
128+
hidi show -d files\People.yml -o People.md -ll trace
129+
```
112130

113131
### Plugin
114132

115133
This command generates an OpenAI style Plugin manifest and minimal OpenAPI file based on the provided API Manifest
116134

117-
**Examples:**
135+
#### Examples:
136+
137+
```bash
138+
hidi plugin -m exampleApiManifest.yml -o mypluginfolder
139+
```
118140

119-
1. hidi plugin -m exampleApiManifest.yml -o mypluginfolder
141+
> Run `hidi plugin -h` to see all the available usage options.

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
1+

22
using System.Collections.Generic;
3+
using System.Net.Http;
34
using Microsoft.OpenApi.Interfaces;
45

56
namespace Microsoft.OpenApi.Models.Interfaces;
@@ -13,7 +14,7 @@ public interface IOpenApiPathItem : IOpenApiDescribedElement, IOpenApiSummarized
1314
/// <summary>
1415
/// Gets the definition of operations on this path.
1516
/// </summary>
16-
public IDictionary<OperationType, OpenApiOperation> Operations { get; }
17+
public IDictionary<HttpMethod, OpenApiOperation> Operations { get; }
1718

1819
/// <summary>
1920
/// An alternative server array to service all operations in this path.

src/Microsoft.OpenApi/Models/OpenApiPathItem.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Net.Http;
67
using Microsoft.OpenApi.Extensions;
78
using Microsoft.OpenApi.Interfaces;
89
using Microsoft.OpenApi.Models.Interfaces;
@@ -22,8 +23,8 @@ public class OpenApiPathItem : IOpenApiExtensible, IOpenApiReferenceable, IOpenA
2223
public string Description { get; set; }
2324

2425
/// <inheritdoc/>
25-
public IDictionary<OperationType, OpenApiOperation> Operations { get; set; }
26-
= new Dictionary<OperationType, OpenApiOperation>();
26+
public IDictionary<HttpMethod, OpenApiOperation> Operations { get; set; }
27+
= new Dictionary<HttpMethod, OpenApiOperation>();
2728

2829
/// <inheritdoc/>
2930
public IList<OpenApiServer> Servers { get; set; } = [];
@@ -39,7 +40,7 @@ public class OpenApiPathItem : IOpenApiExtensible, IOpenApiReferenceable, IOpenA
3940
/// </summary>
4041
/// <param name="operationType">The operation type kind.</param>
4142
/// <param name="operation">The operation item.</param>
42-
public void AddOperation(OperationType operationType, OpenApiOperation operation)
43+
public void AddOperation(HttpMethod operationType, OpenApiOperation operation)
4344
{
4445
Operations[operationType] = operation;
4546
}
@@ -57,7 +58,7 @@ internal OpenApiPathItem(IOpenApiPathItem pathItem)
5758
Utils.CheckArgumentNull(pathItem);
5859
Summary = pathItem.Summary ?? Summary;
5960
Description = pathItem.Description ?? Description;
60-
Operations = pathItem.Operations != null ? new Dictionary<OperationType, OpenApiOperation>(pathItem.Operations) : null;
61+
Operations = pathItem.Operations != null ? new Dictionary<HttpMethod, OpenApiOperation>(pathItem.Operations) : null;
6162
Servers = pathItem.Servers != null ? new List<OpenApiServer>(pathItem.Servers) : null;
6263
Parameters = pathItem.Parameters != null ? new List<IOpenApiParameter>(pathItem.Parameters) : null;
6364
Extensions = pathItem.Extensions != null ? new Dictionary<string, IOpenApiExtension>(pathItem.Extensions) : null;
@@ -92,10 +93,10 @@ public void SerializeAsV2(IOpenApiWriter writer)
9293
// operations except "trace"
9394
foreach (var operation in Operations)
9495
{
95-
if (operation.Key != OperationType.Trace)
96+
if (operation.Key != HttpMethod.Trace)
9697
{
9798
writer.WriteOptionalObject(
98-
operation.Key.GetDisplayName(),
99+
operation.Key.Method.ToLowerInvariant(),
99100
operation.Value,
100101
(w, o) => o.SerializeAsV2(w));
101102
}
@@ -135,7 +136,7 @@ internal virtual void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersio
135136
foreach (var operation in Operations)
136137
{
137138
writer.WriteOptionalObject(
138-
operation.Key.GetDisplayName(),
139+
operation.Key.Method.ToLowerInvariant(),
139140
operation.Value,
140141
callback);
141142
}

src/Microsoft.OpenApi/Models/OperationType.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
5+
using System.Net.Http;
56
using Microsoft.OpenApi.Interfaces;
67
using Microsoft.OpenApi.Models.Interfaces;
78
using Microsoft.OpenApi.Writers;
@@ -64,7 +65,7 @@ public string Description
6465
}
6566

6667
/// <inheritdoc/>
67-
public IDictionary<OperationType, OpenApiOperation> Operations { get => Target?.Operations; }
68+
public IDictionary<HttpMethod, OpenApiOperation> Operations { get => Target?.Operations; }
6869

6970
/// <inheritdoc/>
7071
public IList<OpenApiServer> Servers { get => Target?.Servers; }

0 commit comments

Comments
 (0)