Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/nuget/PublicApiGenerator-11.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Feb 6, 2025
2 parents 55e10fe + 4a6547d commit b002225
Show file tree
Hide file tree
Showing 234 changed files with 3,080 additions and 2,703 deletions.
21 changes: 7 additions & 14 deletions .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ trigger:
branches:
include:
- main
- dev
- support/v1
tags:
include:
- 'v*'
pr:
branches:
include:
- main
- dev
- support/v1
variables:
buildPlatform: 'Any CPU'
Expand Down Expand Up @@ -194,7 +195,7 @@ extends:
content: '*.nupkg'

- stage: deploy
condition: and(or(contains(variables['build.sourceBranch'], 'refs/heads/main'),contains(variables['build.sourceBranch'], 'refs/heads/support/v1')), succeeded())
condition: and(contains(variables['build.sourceBranch'], 'refs/tags/v'), succeeded())
dependsOn: build
jobs:
- deployment: deploy_hidi
Expand Down Expand Up @@ -305,18 +306,10 @@ extends:
condition: succeededOrFailed()
inputs:
gitHubConnection: 'Github-MaggieKimani1'
action: create
action: edit
tagSource: userSpecifiedTag
tag: '$(artifactVersion)'
title: '$(artifactVersion)'
tag: 'v$(artifactVersion)'
releaseNotesSource: inline
assets: '$(Pipeline.Workspace)\**\*.exe'
changeLogType: issueBased
changeLogLabels: '[
{ "label" : "feature-work", "feature", "displayName" : "New Features", "state" : "closed" },
{ "label" : "enhancement", "V2-Enhancement", "displayName" : "Enhancements", "state" : "closed" },
{ "label" : "bug", "bug-fix", "displayName" : "Bugs", "state" : "closed" },
{ "label" : "documentation", "doc", "displayName" : "Documentation", "state" : "closed"},
{ "label" : "dependencies", "displayName" : "Package Updates", "state" : "closed" }
]'
addChangeLog: false

7 changes: 7 additions & 0 deletions .github/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
manifest: true
primaryBranch: main
handleGHRelease: true
branches:
- branch: support/v1
manifest: true
handleGHRelease: true
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CodeQL Analysis

on:
push:
branches: [ main, dev ]
branches: [ main, support/v1 ]
pull_request:
schedule:
- cron: '0 8 * * *'
Expand Down
22 changes: 17 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ name: Publish Docker image
on:
workflow_dispatch:
push:
branches: [main, dev, support/v1]
paths: ['src/Microsoft.OpenApi.Hidi/**', '.github/workflows/**']
tags: ["v*"]
branches: [main]
pull_request:
env:
REGISTRY: msgraphprod.azurecr.io
IMAGE_NAME: public/openapi/hidi
PREVIEW_BRANCH: "refs/heads/main"
jobs:
push_to_registry:
environment:
Expand All @@ -28,14 +30,24 @@ jobs:
echo "::set-output name=version::${version}"
shell: pwsh
id: getversion
- name: Get truncated run number
if: contains(github.ref, env.PREVIEW_BRANCH)
id: runnumber
run: echo "runnumber=$(echo ${{ github.run_number }} | awk '{ print substr($0, length($0)-3, length($0)) }')" >> $GITHUB_OUTPUT
- name: Get current date
if: contains(github.ref, env.PREVIEW_BRANCH)
id: date
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
- name: Push to registry - Nightly
if: ${{ github.ref == 'refs/heads/dev' }}
if: contains(github.ref, env.PREVIEW_BRANCH)
uses: docker/[email protected]
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }}-preview.${{ steps.date.outputs.date }}${{ steps.runnumber.outputs.runnumber }}
build-args: |
version_suffix=preview.${{ steps.date.outputs.date }}${{ steps.runnumber.outputs.runnumber }}
- name: Push to registry - Release
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/support/v1' }}
if: contains(github.ref, 'refs/tags/v')
uses: docker/[email protected]
with:
push: true
Expand Down
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "2.0.0-preview7"
}
153 changes: 153 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Contributing to OpenAPI.net

OpenAPI.net is a mono-repo containing source code for the following packages:

## Libraries

| Library | NuGet Release |
|----------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Microsoft.OpenAPI](./src/Microsoft.OpenAPI/README.md) | [![NuGet Version](https://img.shields.io/nuget/vpre/Microsoft.OpenAPI?label=Latest&logo=nuget)](https://www.nuget.org/packages/Microsoft.OpenAPI/) |
| [Microsoft.OpenAPI.Readers](./src/Microsoft.OpenAPI.Readers/README.md) | [![NuGet Version](https://img.shields.io/nuget/vpre/Microsoft.OpenAPI.Readers?label=Latest&logo=nuget)](https://www.nuget.org/packages/Microsoft.OpenAPI.Readers/) |
| [Microsoft.OpenAPI.Hidi](./src/Microsoft.OpenAPI.Hidi/README.md) | [![NuGet Version](https://img.shields.io/nuget/vpre/Microsoft.OpenAPI.Hidi?label=Latest&logo=nuget)](https://www.nuget.org/packages/Microsoft.OpenAPI.Hidi/) |

OpenAPI.net is open to contributions. There are a couple of different recommended paths to get contributions into the released version of this library.

__NOTE__ A signed a contribution license agreement is required for all contributions, and is checked automatically on new pull requests. Please read and sign [the agreement](https://cla.microsoft.com/) before starting any work for this repository.

## File issues

The best way to get started with a contribution is to start a dialog with the owners of this repository. Sometimes features will be under development or out of scope for this SDK and it's best to check before starting work on contribution. Discussions on bugs and potential fixes could point you to the write change to make.

## Submit pull requests for bug fixes and features

Feel free to submit a pull request with a linked issue against the __main__ branch. The main branch will be updated frequently.
## Commit message format

To support our automated release process, pull requests are required to follow the [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/)
format.
Each commit message consists of a __header__, an optional __body__ and an optional __footer__. The header is the first line of the commit and
MUST have a __type__ (see below for a list of types) and a __description__. An optional __scope__ can be added to the header to give extra context.

```
<type>[optional scope]: <short description>
<BLANK LINE>
<optional body>
<BLANK LINE>
<optional footer(s)>
```

The recommended commit types used are:

- __feat__ for feature updates (increments the _minor_ version)
- __fix__ for bug fixes (increments the _patch_ version)
- __perf__ for performance related changes e.g. optimizing an algorithm
- __refactor__ for code refactoring changes
- __test__ for test suite updates e.g. adding a test or fixing a test
- __style__ for changes that don't affect the meaning of code. e.g. formatting changes
- __docs__ for documentation updates e.g. ReadMe update or code documentation updates
- __build__ for build system changes (gradle updates, external dependency updates)
- __ci__ for CI configuration file changes e.g. updating a pipeline
- __chore__ for miscallaneous non-sdk changesin the repo e.g. removing an unused file

Adding an exclamation mark after the commit type (`feat!`) or footer with the prefix __BREAKING CHANGE:__ will cause an increment of the _major_ version.
5 changes: 2 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
<PackageProjectUrl>https://github.com/Microsoft/OpenAPI.NET</PackageProjectUrl>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
<Version>2.0.0-preview7</Version>
</PropertyGroup>
<!-- https://github.com/clairernovotny/DeterministicBuilds#deterministic-builds -->
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference
Condition="!$(MSBuildProjectName.EndsWith('Tests'))"
Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Condition="!$(MSBuildProjectName.EndsWith('Tests'))" Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
</ItemGroup>
</Project>
33 changes: 33 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"bootstrap-sha": "8943e2ad40babb0204dedb11ad6f9273adf9cd53",
"exclude-paths": [
".azure-pipelines",
".github",
".idea",
".vs",
".vscode"
],
"release-type": "simple",
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"include-component-in-tag": false,
"include-v-in-tag": true,
"draft": false,
"prerelease": true,
"versioning": "prerelease",
"prerelease-type": "preview",
"packages": {
".": {
"package-name": "Microsoft.OpenApi",
"changelog-path": "CHANGELOG.md",
"extra-files": [
{
"type": "xml",
"path": "Directory.Build.props",
"xpath": "//Project/PropertyGroup/Version"
}
]
}
},
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
}
47 changes: 18 additions & 29 deletions src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class PowerShellFormatter : OpenApiVisitorBase
{
private const string DefaultPutPrefix = ".Update";
private const string PowerShellPutPrefix = ".Set";
private readonly Stack<OpenApiSchema> _schemaLoop = new();
private readonly Stack<IOpenApiSchema> _schemaLoop = new();
private static readonly Regex s_oDataCastRegex = new("(.*(?<=[a-z]))\\.(As(?=[A-Z]).*)", RegexOptions.Compiled, TimeSpan.FromSeconds(5));
private static readonly Regex s_hashSuffixRegex = new(@"^[^-]+", RegexOptions.Compiled, TimeSpan.FromSeconds(5));
private static readonly Regex s_oDataRefRegex = new("(?<=[a-z])Ref(?=[A-Z])", RegexOptions.Compiled, TimeSpan.FromSeconds(5));
Expand All @@ -42,7 +42,7 @@ static PowerShellFormatter()
// 5. Fix anyOf and oneOf schema.
// 6. Add AdditionalProperties to object schemas.

public override void Visit(OpenApiSchema schema)
public override void Visit(IOpenApiSchema schema)
{
AddAdditionalPropertiesToSchema(schema);
ResolveAnyOfSchema(schema);
Expand Down Expand Up @@ -165,22 +165,22 @@ private static void ResolveFunctionParameters(IList<IOpenApiParameter> parameter
// Replace content with a schema object of type array
// for structured or collection-valued function parameters
parameter.Content = null;
parameter.Schema = new()
parameter.Schema = new OpenApiSchema()
{
Type = JsonSchemaType.Array,
Items = new()
Items = new OpenApiSchema()
{
Type = JsonSchemaType.String
}
};
}
}

private void AddAdditionalPropertiesToSchema(OpenApiSchema schema)
private void AddAdditionalPropertiesToSchema(IOpenApiSchema schema)
{
if (schema != null && !_schemaLoop.Contains(schema) && schema.Type.Equals(JsonSchemaType.Object))
if (schema is OpenApiSchema openApiSchema && !_schemaLoop.Contains(schema) && schema.Type.Equals(JsonSchemaType.Object))
{
schema.AdditionalProperties = new() { Type = JsonSchemaType.Object };
openApiSchema.AdditionalProperties = new OpenApiSchema() { Type = JsonSchemaType.Object };

/* Because 'additionalProperties' are now being walked,
* we need a way to keep track of visited schemas to avoid
Expand All @@ -190,39 +190,29 @@ private void AddAdditionalPropertiesToSchema(OpenApiSchema schema)
}
}

private static void ResolveOneOfSchema(OpenApiSchema schema)
private static void ResolveOneOfSchema(IOpenApiSchema schema)
{
if (schema.OneOf?.FirstOrDefault() is { } newSchema)
if (schema is OpenApiSchema openApiSchema && schema.OneOf?.FirstOrDefault() is OpenApiSchema newSchema)
{
schema.OneOf = null;
FlattenSchema(schema, newSchema);
openApiSchema.OneOf = null;
FlattenSchema(openApiSchema, newSchema);
}
}

private static void ResolveAnyOfSchema(OpenApiSchema schema)
private static void ResolveAnyOfSchema(IOpenApiSchema schema)
{
if (schema.AnyOf?.FirstOrDefault() is { } newSchema)
if (schema is OpenApiSchema openApiSchema && schema.AnyOf?.FirstOrDefault() is OpenApiSchema newSchema)
{
schema.AnyOf = null;
FlattenSchema(schema, newSchema);
openApiSchema.AnyOf = null;
FlattenSchema(openApiSchema, newSchema);
}
}

private static void FlattenSchema(OpenApiSchema schema, OpenApiSchema newSchema)
{
if (newSchema != null)
{
if (newSchema.Reference != null)
{
schema.Reference = newSchema.Reference;
schema.UnresolvedReference = true;
}
else
{
// Copies schema properties based on https://github.com/microsoft/OpenAPI.NET.OData/pull/264.
CopySchema(schema, newSchema);
}
}
if (newSchema is null) return;
// Copies schema properties based on https://github.com/microsoft/OpenAPI.NET.OData/pull/264.
CopySchema(schema, newSchema);
}

private static void CopySchema(OpenApiSchema schema, OpenApiSchema newSchema)
Expand Down Expand Up @@ -253,7 +243,6 @@ private static void CopySchema(OpenApiSchema schema, OpenApiSchema newSchema)
schema.Enum ??= newSchema.Enum;
schema.ReadOnly = !schema.ReadOnly ? newSchema.ReadOnly : schema.ReadOnly;
schema.WriteOnly = !schema.WriteOnly ? newSchema.WriteOnly : schema.WriteOnly;
schema.Nullable = !schema.Nullable ? newSchema.Nullable : schema.Nullable;
schema.Deprecated = !schema.Deprecated ? newSchema.Deprecated : schema.Deprecated;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<Nullable>enable</Nullable>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>2.0.0-preview5</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand Down
9 changes: 4 additions & 5 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options,
else if (!string.IsNullOrEmpty(options.OpenApi))
{
stream = await GetStreamAsync(options.OpenApi, logger, cancellationToken).ConfigureAwait(false);
var result = await ParseOpenApiAsync(options.OpenApi, format, options.InlineExternal, logger, stream, cancellationToken).ConfigureAwait(false);
var result = await ParseOpenApiAsync(options.OpenApi, options.InlineExternal, logger, stream, cancellationToken).ConfigureAwait(false);
document = result.Document;
}
else throw new InvalidOperationException("No input file path or URL provided");
Expand Down Expand Up @@ -351,8 +351,7 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
try
{
using var stream = await GetStreamAsync(openApi, logger, cancellationToken).ConfigureAwait(false);
var openApiFormat = !string.IsNullOrEmpty(openApi) ? GetOpenApiFormat(openApi, logger) : OpenApiFormat.Yaml;
result = await ParseOpenApiAsync(openApi, openApiFormat.GetDisplayName(),false, logger, stream, cancellationToken).ConfigureAwait(false);
result = await ParseOpenApiAsync(openApi, false, logger, stream, cancellationToken).ConfigureAwait(false);

using (logger.BeginScope("Calculating statistics"))
{
Expand Down Expand Up @@ -380,7 +379,7 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
return result.Diagnostic.Errors.Count == 0;
}

private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, string format, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken = default)
private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken = default)
{
ReadResult result;
var stopwatch = Stopwatch.StartNew();
Expand All @@ -396,7 +395,7 @@ private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, stri
new Uri("file://" + new FileInfo(openApiFile).DirectoryName + Path.DirectorySeparatorChar)
};

result = await OpenApiDocument.LoadAsync(stream, format, settings, cancellationToken).ConfigureAwait(false);
result = await OpenApiDocument.LoadAsync(stream, settings: settings, cancellationToken: cancellationToken).ConfigureAwait(false);

logger.LogTrace("{Timestamp}ms: Completed parsing.", stopwatch.ElapsedMilliseconds);

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/StatsVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void Visit(IOpenApiParameter parameter)

public int SchemaCount { get; set; }

public override void Visit(OpenApiSchema schema)
public override void Visit(IOpenApiSchema schema)
{
SchemaCount++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<!-- net6.0 target is present because of the conditional build in OpenApiYamlReader.Read -->
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.0-preview5</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<SignAssembly>true</SignAssembly>
<IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net5.0'))">true</IsTrimmable>
Expand Down
Loading

0 comments on commit b002225

Please sign in to comment.