Skip to content

Commit 0298364

Browse files
committed
Merge branch 'vnext' into mk/add-copy-constructors-for-models
2 parents c61e1cb + a9ca6e9 commit 0298364

File tree

20 files changed

+338
-49
lines changed

20 files changed

+338
-49
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
- name: Initialize CodeQL
2525
id: init_codeql
26-
uses: github/codeql-action/init@v1
26+
uses: github/codeql-action/init@v2
2727
with:
2828
queries: security-and-quality
2929

@@ -43,6 +43,6 @@ jobs:
4343
4444
- name: Perform CodeQL Analysis
4545
id: analyze_codeql
46-
uses: github/codeql-action/analyze@v1
46+
uses: github/codeql-action/analyze@v2
4747

4848
# Built with ❤ by [Pipeline Foundation](https://pipeline.foundation)

.github/workflows/docker.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Publish Docker image
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches: [master, vnext]
6+
paths: ['src/Microsoft.OpenApi.Hidi/**', '.github/workflows/**']
7+
env:
8+
REGISTRY: msgraphprod.azurecr.io
9+
IMAGE_NAME: public/hidi
10+
jobs:
11+
push_to_registry:
12+
environment:
13+
name: acr
14+
name: Push Docker image
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Check out the repo
18+
uses: actions/checkout@v3
19+
- name: Login to GitHub package feed
20+
uses: docker/[email protected]
21+
with:
22+
username: ${{ secrets.ACR_USERNAME }}
23+
password: ${{ secrets.ACR_PASSWORD }}
24+
registry: ${{ env.REGISTRY }}
25+
- run: |
26+
$content = [XML](Get-Content ./src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj)
27+
$version = $content.Project.PropertyGroup.Version
28+
echo "::set-output name=version::${version}"
29+
shell: pwsh
30+
id: getversion
31+
- name: Push to GitHub Packages - Nightly
32+
if: ${{ github.ref == 'refs/heads/vnext' }}
33+
uses: docker/[email protected]
34+
with:
35+
push: true
36+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly
37+
- name: Push to GitHub Packages - Release
38+
if: ${{ github.ref == 'refs/heads/master' }}
39+
uses: docker/[email protected]
40+
with:
41+
push: true
42+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }}

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
2+
WORKDIR /app
3+
4+
COPY ./src ./hidi/src
5+
WORKDIR /app/hidi
6+
RUN dotnet publish ./src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj -c Release
7+
8+
FROM mcr.microsoft.com/dotnet/runtime:6.0 as runtime
9+
WORKDIR /app
10+
11+
COPY --from=build-env /app/hidi/src/Microsoft.OpenApi.Hidi/bin/Release/net6.0 ./
12+
13+
VOLUME /app/output
14+
VOLUME /app/openapi.yml
15+
VOLUME /app/api.csdl
16+
VOLUME /app/collection.json
17+
ENV HIDI_CONTAINER=true DOTNET_TieredPGO=1 DOTNET_TC_QuickJitForLoops=1
18+
ENTRYPOINT ["dotnet", "Microsoft.OpenApi.Hidi.dll"]
19+
LABEL description="# Welcome to Hidi \
20+
To start transforming OpenAPI documents checkout [the getting started documentation](https://github.com/microsoft/OpenAPI.NET/tree/vnext/src/Microsoft.OpenApi.Hidi) \
21+
[Source dockerfile](https://github.com/microsoft/OpenAPI.NET/blob/vnext/Dockerfile)"

SECURITY.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.6 BLOCK -->
2+
3+
## Security
4+
5+
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
6+
7+
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below.
8+
9+
## Reporting Security Issues
10+
11+
**Please do not report security vulnerabilities through public GitHub issues.**
12+
13+
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
14+
15+
If you prefer to submit without logging in, send email to [[email protected]](mailto:[email protected]). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/msrc/pgp-key-msrc).
16+
17+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
18+
19+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20+
21+
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22+
* Full paths of source file(s) related to the manifestation of the issue
23+
* The location of the affected source code (tag/branch/commit or direct URL)
24+
* Any special configuration required to reproduce the issue
25+
* Step-by-step instructions to reproduce the issue
26+
* Proof-of-concept or exploit code (if possible)
27+
* Impact of the issue, including how an attacker might exploit the issue
28+
29+
This information will help us triage your report more quickly.
30+
31+
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs.
32+
33+
## Preferred Languages
34+
35+
We prefer all communications to be in English.
36+
37+
## Policy
38+
39+
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/msrc/cvd).
40+
41+
<!-- END MICROSOFT SECURITY.MD BLOCK -->

src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
1616
<ToolCommandName>hidi</ToolCommandName>
1717
<PackageOutputPath>./../../artifacts</PackageOutputPath>
18-
<Version>1.0.0-preview1</Version>
18+
<Version>1.0.0-preview6</Version>
1919
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
2020
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2121
<PackageTags>OpenAPI .NET</PackageTags>
2222
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET</RepositoryUrl>
2323
<PackageReleaseNotes>
24-
- Upgrades Microsoft.OpenApi.OData to 1.0.10-preview1
25-
- Fixes an issue where hidi would not process async operations
24+
- Bumps up the Microsoft.OpenAPI library to v1.3.2
25+
- Bumps up the Microsoft.OData library to v7.12.0
26+
- Bumps up the Microsoft.OpenApi.OData library to v1.0.11-preview3
2627
</PackageReleaseNotes>
2728
<AssemblyName>Microsoft.OpenApi.Hidi</AssemblyName>
2829
<RootNamespace>Microsoft.OpenApi.Hidi</RootNamespace>
@@ -45,8 +46,8 @@
4546
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
4647
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
4748
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
48-
<PackageReference Include="Microsoft.OData.Edm" Version="7.10.0" />
49-
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.0.10-preview3" />
49+
<PackageReference Include="Microsoft.OData.Edm" Version="7.12.0" />
50+
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.0.11-preview3" />
5051
</ItemGroup>
5152

5253
<ItemGroup>

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public static async Task<int> TransformOpenApiDocument(
5454
CancellationToken cancellationToken
5555
)
5656
{
57-
var logger = ConfigureLoggerInstance(loglevel);
57+
using var loggerFactory = ConfigureLoggerInstance(loglevel);
58+
var logger = loggerFactory.CreateLogger<OpenApiService>();
5859

5960
try
6061
{
@@ -258,7 +259,8 @@ public static async Task<int> ValidateOpenApiDocument(
258259
LogLevel loglevel,
259260
CancellationToken cancellationToken)
260261
{
261-
var logger = ConfigureLoggerInstance(loglevel);
262+
using var loggerFactory = ConfigureLoggerInstance(loglevel);
263+
var logger = loggerFactory.CreateLogger<OpenApiService>();
262264

263265
try
264266
{
@@ -343,11 +345,12 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl)
343345
PrefixEntityTypeNameBeforeKey = true,
344346
TagDepth = 2,
345347
EnablePagination = true,
346-
EnableDiscriminatorValue = false,
348+
EnableDiscriminatorValue = true,
347349
EnableDerivedTypesReferencesForRequestBody = false,
348350
EnableDerivedTypesReferencesForResponses = false,
349351
ShowRootPath = false,
350-
ShowLinks = false
352+
ShowLinks = false,
353+
ExpandDerivedTypesNavigationProperties = false
351354
};
352355
OpenApiDocument document = edmModel.ConvertToOpenApi(settings);
353356

@@ -572,14 +575,14 @@ private static OpenApiFormat GetOpenApiFormat(string input, ILogger logger)
572575
return !input.StartsWith("http") && Path.GetExtension(input) == ".json" ? OpenApiFormat.Json : OpenApiFormat.Yaml;
573576
}
574577

575-
private static ILogger ConfigureLoggerInstance(LogLevel loglevel)
578+
private static ILoggerFactory ConfigureLoggerInstance(LogLevel loglevel)
576579
{
577580
// Configure logger options
578581
#if DEBUG
579582
loglevel = loglevel > LogLevel.Debug ? LogLevel.Debug : loglevel;
580583
#endif
581584

582-
var logger = LoggerFactory.Create((builder) => {
585+
return LoggerFactory.Create((builder) => {
583586
builder
584587
.AddSimpleConsole(c => {
585588
c.IncludeScopes = true;
@@ -588,9 +591,7 @@ private static ILogger ConfigureLoggerInstance(LogLevel loglevel)
588591
.AddDebug()
589592
#endif
590593
.SetMinimumLevel(loglevel);
591-
}).CreateLogger<OpenApiService>();
592-
593-
return logger;
594+
});
594595
}
595596
}
596597
}

src/Microsoft.OpenApi.Hidi/Program.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ static async Task Main(string[] args)
2222
descriptionOption.AddAlias("-d");
2323

2424
var csdlOption = new Option<string>("--csdl", "Input CSDL file path or URL");
25-
csdlOption.AddAlias("-cs");
25+
csdlOption.AddAlias("--cs");
2626

2727
var csdlFilterOption = new Option<string>("--csdl-filter", "Comma delimited list of EntitySets or Singletons to filter CSDL on. e.g. tasks,accounts");
28-
csdlFilterOption.AddAlias("-csf");
28+
csdlFilterOption.AddAlias("--csf");
2929

3030
var outputOption = new Option<FileInfo>("--output", () => new FileInfo("./output"), "The output directory path for the generated file.") { Arity = ArgumentArity.ZeroOrOne };
3131
outputOption.AddAlias("-o");
3232

3333
var cleanOutputOption = new Option<bool>("--clean-output", "Overwrite an existing file");
34-
cleanOutputOption.AddAlias("-co");
34+
cleanOutputOption.AddAlias("--co");
3535

3636
var versionOption = new Option<string?>("--version", "OpenAPI specification version");
3737
versionOption.AddAlias("-v");
@@ -40,25 +40,25 @@ static async Task Main(string[] args)
4040
formatOption.AddAlias("-f");
4141

4242
var terseOutputOption = new Option<bool>("--terse-output", "Produce terse json output");
43-
terseOutputOption.AddAlias("-to");
43+
terseOutputOption.AddAlias("--to");
4444

45-
var logLevelOption = new Option<LogLevel>("--loglevel", () => LogLevel.Information, "The log level to use when logging messages to the main output.");
46-
logLevelOption.AddAlias("-ll");
45+
var logLevelOption = new Option<LogLevel>("--log-level", () => LogLevel.Information, "The log level to use when logging messages to the main output.");
46+
logLevelOption.AddAlias("--ll");
4747

4848
var filterByOperationIdsOption = new Option<string>("--filter-by-operationids", "Filters OpenApiDocument by comma delimited list of OperationId(s) provided");
49-
filterByOperationIdsOption.AddAlias("-op");
49+
filterByOperationIdsOption.AddAlias("--op");
5050

5151
var filterByTagsOption = new Option<string>("--filter-by-tags", "Filters OpenApiDocument by comma delimited list of Tag(s) provided. Also accepts a single regex.");
52-
filterByTagsOption.AddAlias("-t");
52+
filterByTagsOption.AddAlias("--t");
5353

5454
var filterByCollectionOption = new Option<string>("--filter-by-collection", "Filters OpenApiDocument by Postman collection provided. Provide path to collection file.");
5555
filterByCollectionOption.AddAlias("-c");
5656

57-
var inlineLocalOption = new Option<bool>("--inlineLocal", "Inline local $ref instances");
58-
inlineLocalOption.AddAlias("-il");
57+
var inlineLocalOption = new Option<bool>("--inline-local", "Inline local $ref instances");
58+
inlineLocalOption.AddAlias("--il");
5959

60-
var inlineExternalOption = new Option<bool>("--inlineExternal", "Inline external $ref instances");
61-
inlineExternalOption.AddAlias("-ie");
60+
var inlineExternalOption = new Option<bool>("--inline-external", "Inline external $ref instances");
61+
inlineExternalOption.AddAlias("--ie");
6262

6363
var validateCommand = new Command("validate")
6464
{

src/Microsoft.OpenApi.Hidi/readme.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Overview
2+
3+
Hidi is a command line tool that makes it easy to work with and transform OpenAPI documents. The tool enables you validate and apply transformations to and from different file formats using various commands to do different actions on the files.
4+
5+
## Capabilities
6+
Hidi has these key capabilities that enable you to build different scenarios off the tool
7+
8+
• Validation of OpenAPI files
9+
• Conversion of OpenAPI files into different file formats: convert files from JSON to YAML, YAML to JSON
10+
• Slice or filter OpenAPI documents to smaller subsets using operationIDs and tags
11+
12+
13+
## Installation
14+
15+
Install [Microsoft.OpenApi.Hidi](https://www.nuget.org/packages/Microsoft.OpenApi.Hidi/1.0.0-preview4) package from NuGet by running the following command:
16+
17+
### .NET CLI(Global)
18+
1. dotnet tool install --global Microsoft.OpenApi.Hidi --prerelease
19+
20+
21+
### .NET CLI(local)
22+
23+
1. dotnet new tool-manifest #if you are setting up the OpenAPI.NET repo
24+
2. dotnet tool install --local Microsoft.OpenApi.Hidi --prerelease
25+
26+
27+
28+
29+
## How to use Hidi
30+
Once you've installed the package locally, you can invoke the Hidi by running: hidi [command].
31+
You can access the list of command options we have by running hidi -h
32+
The tool avails the following commands:
33+
34+
• Validate
35+
• Transform
36+
37+
### Validate
38+
This command option accepts an OpenAPI document as an input parameter, visits multiple OpenAPI elements within the document and returns statistics count report on the following elements:
39+
40+
• Path Items
41+
• Operations
42+
• Parameters
43+
• Request bodies
44+
• Responses
45+
• Links
46+
• Callbacks
47+
• Schemas
48+
49+
It accepts the following command:
50+
51+
• --openapi(-d) - OpenAPI description file path or URL
52+
• --loglevel(-ll) - The log level to use when logging messages to the main output
53+
54+
55+
**Example:** `hidi.exe validate --openapi C:\OpenApidocs\Mail.yml --loglevel trace`
56+
57+
Run validate -h to see the options available.
58+
59+
### Transform
60+
Used to convert file formats from JSON to YAML and vice versa and performs slicing of OpenAPI documents.
61+
62+
This command accepts the following parameters:
63+
64+
• --openapi(-d) - OpenAPI description file path in the local filesystem or a valid URL hosted on a HTTPS server
65+
• --csdl(-cs) - CSDL file path in the local filesystem or a valid URL hosted on a HTTPS server
66+
• --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.
67+
• --output(-o) - Output directory path for the transformed document
68+
• --clean-ouput(-co) - an optional param that allows a user to overwrite an existing file.
69+
• --version(-v) - OpenAPI specification version
70+
• --format(-f) - File format
71+
• --loglevel(-ll) - The log level to use when logging messages to the main output
72+
• --inline(-i) - Inline $ref instances
73+
• --resolveExternal(-ex) - Resolve external $refs
74+
• --filterByOperationIds(-op) - Slice document based on OperationId(s) provided. Accepts a comma delimited list of operation ids.
75+
• --filterByTags(-t) - Slice document based on tag(s) provided. Accepts a comma delimited list of tags.
76+
• --filterByCollection(-c) - Slices the OpenAPI document based on the Postman Collection file generated by Resource Explorer
77+
78+
**Examples:**
79+
80+
1. Filtering by OperationIds
81+
hidi transform -d files\People.yml -f yaml -o files\People.yml -v OpenApi3_0 -op users_UpdateInsights -co
82+
83+
2. Filtering by Postman collection
84+
hidi transform --openapi files\People.yml --format yaml --output files\People2.yml --version OpenApi3_0 --filterByCollection Graph-Collection-0017059134807617005.postman_collection.json
85+
86+
3. CSDL--->OpenAPI conversion and filtering
87+
hidi transform --input Files/Todo.xml --output Files/Todo-subset.yml --format yaml --version OpenApi3_0 --filterByOperationIds Todos.Todo.UpdateTodo
88+
89+
4. CSDL Filtering by EntitySets and Singletons
90+
hidi transform -cs dataverse.csdl --csdlFilter "appointments,opportunities" -o appointmentsAndOpportunities.yaml -ll trace
91+
92+
Run transform -h to see all the available usage options.

src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
<Company>Microsoft</Company>
1111
<Title>Microsoft.OpenApi.Readers</Title>
1212
<PackageId>Microsoft.OpenApi.Readers</PackageId>
13-
<Version>1.3.1</Version>
13+
<Version>1.3.2</Version>
1414
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
1515
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1616
<PackageTags>OpenAPI .NET</PackageTags>
1717
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET</RepositoryUrl>
1818
<PackageReleaseNotes>
19-
- Publish symbols.
19+
- Fixed a bug where contact information would not read properly. #892
2020
</PackageReleaseNotes>
2121
<AssemblyName>Microsoft.OpenApi.Readers</AssemblyName>
2222
<RootNamespace>Microsoft.OpenApi.Readers</RootNamespace>
@@ -40,7 +40,7 @@
4040
</ItemGroup>
4141

4242
<ItemGroup>
43-
<PackageReference Include="SharpYaml" Version="1.9.0" />
43+
<PackageReference Include="SharpYaml" Version="1.9.2" />
4444
</ItemGroup>
4545

4646
<ItemGroup>

src/Microsoft.OpenApi.Readers/V2/OpenApiV2VersionService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public OpenApiV2VersionService(OpenApiDiagnostic diagnostic)
3434
private IDictionary<Type, Func<ParseNode, object>> _loaders = new Dictionary<Type, Func<ParseNode, object>>
3535
{
3636
[typeof(IOpenApiAny)] = OpenApiV2Deserializer.LoadAny,
37+
[typeof(OpenApiContact)] = OpenApiV2Deserializer.LoadContact,
3738
[typeof(OpenApiExternalDocs)] = OpenApiV2Deserializer.LoadExternalDocs,
3839
[typeof(OpenApiHeader)] = OpenApiV2Deserializer.LoadHeader,
3940
[typeof(OpenApiInfo)] = OpenApiV2Deserializer.LoadInfo,

0 commit comments

Comments
 (0)