Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
52981d4
fix: a flaky behaviour for format property serialization
baywet Jan 22, 2025
3ea1fa9
Merge pull request #2079 from microsoft/fix/flaky-format
baywet Jan 22, 2025
8a2b07c
chore: linting
baywet Jan 21, 2025
b84ea19
fix: request body references are converted to v2 properly
baywet Jan 22, 2025
03436cb
chore: adds unit test for v2 request body reference fix
baywet Jan 22, 2025
4243873
fix: open api response reference should not clone objects
baywet Jan 22, 2025
4af0878
Merge pull request #2083 from microsoft/fix/request-body-reference-v2
baywet Jan 23, 2025
2bca1df
Merge pull request #2084 from microsoft/fix/response-reference
baywet Jan 23, 2025
7405f3c
feat: makes the reference interface covariant
baywet Jan 23, 2025
dc8a757
fix: visibility of serialize internal methods
baywet Jan 23, 2025
cc28ff2
fix: proxy design pattern implementation for OpenAPiExample
baywet Jan 24, 2025
2cbb0fa
fix: callback reference proxy implementation
baywet Jan 24, 2025
dc2ce69
chore: adds a todo for later
baywet Jan 24, 2025
af3038a
fix: removes useless virtual definitions in components
baywet Jan 24, 2025
2a10cd9
feat: splits described and summarized interfaces
baywet Jan 24, 2025
68b25cc
fix: aligns callback parameter name with interface
baywet Jan 24, 2025
d7e1f91
fix: aligns parameter name with interface definition for example
baywet Jan 24, 2025
77e0ad1
fix: Open API header proxy design pattern implementation
baywet Jan 24, 2025
aa80b19
fix: do not allow null argument for example copy constructor
baywet Jan 24, 2025
0cb4ccb
fix: adds missing null propagation operators for callback and header …
baywet Jan 24, 2025
376e54d
fix: open API link reference proxy design pattern implementation
baywet Jan 24, 2025
079ab11
Merge pull request #2089 from microsoft/fix/example-reference
baywet Jan 24, 2025
aa993b1
fix: removes unnecessary null prop in copy constructor
baywet Jan 24, 2025
eeb79a4
fix: parameter reference proxy design pattern implementation
baywet Jan 24, 2025
1006879
fix: extraneous null prop removal
baywet Jan 24, 2025
028d60b
Merge pull request #2090 from microsoft/fix/callback-reference
baywet Jan 27, 2025
4df4b26
chore: refactors common reference work to a base class to reduce dupl…
baywet Jan 27, 2025
8c2c188
chore: typo fix
baywet Jan 27, 2025
aad26b4
chore: removes duplicated serialize internal method
baywet Jan 27, 2025
a72aa29
chore: removes duplicated serialization method implementation for ref…
baywet Jan 27, 2025
c725267
fix: path item reference implementation
baywet Jan 27, 2025
8361069
fix: adds missing null prop operator to proxy properties
baywet Jan 27, 2025
45e40fa
fix: returns reference instead of null
baywet Jan 27, 2025
88badd4
chore: aligns test definition with other tests
baywet Jan 27, 2025
425335e
fix: proxy design pattern implementation for request body
baywet Jan 27, 2025
704943c
fix: fixes inlining override when they should not happen
baywet Jan 27, 2025
9b6147a
chore: adds additional test cases for parameter reference inlining
baywet Jan 27, 2025
66dcb21
chore: adds unit tests for callback and path item
baywet Jan 27, 2025
2faeb0b
chore: adds tests for example reference inlining
baywet Jan 27, 2025
cbda1f4
chore: adds unit tests for headers reference inlining
baywet Jan 27, 2025
7afeabe
chore: adds unit tests for link reference inlining
baywet Jan 27, 2025
88ad997
fix: references callback writer
baywet Jan 27, 2025
5b4003b
fix: response reference proxy design pattern implementation
baywet Jan 27, 2025
4060938
chore(deps): bump dependabot/fetch-metadata from 2.2.0 to 2.3.0
dependabot[bot] Jan 27, 2025
bf00f92
chore(deps): bump docker/build-push-action from 6.12.0 to 6.13.0
dependabot[bot] Jan 27, 2025
90d87f4
Merge pull request #2102 from microsoft/dependabot/github_actions/doc…
baywet Jan 27, 2025
16ba957
Merge pull request #2101 from microsoft/dependabot/github_actions/dep…
baywet Jan 27, 2025
61e6a40
Updated for https://dev.azure.com/microsoftgraph/0985d294-5762-4bc2-a…
microsoft-github-policy-service[bot] Jan 27, 2025
1b65d40
Merge pull request #2091 from microsoft/fix/headers-reference
baywet Jan 28, 2025
694a74b
Merge pull request #2103 from microsoft/users/merlinbot/1es-pt-auto-b…
MaggieKimani1 Jan 28, 2025
6a96462
Merge pull request #2092 from microsoft/fix/link-reference
MaggieKimani1 Jan 28, 2025
ed6ffa1
Merge pull request #2093 from microsoft/fix/parameter-reference
MaggieKimani1 Jan 28, 2025
ee4d4c3
Merge pull request #2095 from microsoft/chore/references-refactoring
MaggieKimani1 Jan 28, 2025
56f291b
Merge pull request #2096 from microsoft/fix/path-item-reference
MaggieKimani1 Jan 28, 2025
817acac
Merge pull request #2097 from microsoft/fix/request-body-reference
MaggieKimani1 Jan 28, 2025
df0aafb
Merge pull request #2098 from microsoft/chore/additional-reference-in…
MaggieKimani1 Jan 28, 2025
8103c20
Merge pull request #2099 from microsoft/fix/response-reference
MaggieKimani1 Jan 28, 2025
aebefb7
fix: open api schema reference proxy design pattern implementation
baywet Jan 28, 2025
41759a1
fix: missing doc comment for annotations
baywet Jan 28, 2025
4dfc9b8
fix: removes virtual modifier in MediaType
baywet Jan 28, 2025
21253f6
chore: reduce fluent assertion usage
baywet Jan 28, 2025
1bd2624
fix: draft security scheme reference proxy design pattern
baywet Jan 29, 2025
ea68427
fix: build passes
baywet Jan 29, 2025
4aad962
chore: updates public api export
baywet Jan 29, 2025
9b392a6
chore: updates test files for security scheme references
baywet Jan 29, 2025
3c7c894
chore: updates public api export
baywet Jan 29, 2025
837f000
fix: fixes invalid OAI document for unit tests
baywet Jan 29, 2025
d2e4111
fix: failing unit tests for security scheme references in security re…
baywet Jan 29, 2025
1c6fd8e
fix: an empty security requirement should not result in an object dur…
baywet Jan 29, 2025
f0cd02c
Revert "fix: an empty security requirement should not result in an ob…
baywet Jan 29, 2025
42bd396
fix: empty security requirements are actually valid. to negate the do…
baywet Jan 29, 2025
b17a552
chore: code linting
baywet Jan 29, 2025
8ff367b
chore: adds missing string comparison
baywet Jan 29, 2025
df91f8d
chore: use constant for extension mechanism
baywet Jan 29, 2025
3cb80af
chore: adds missing string comparison in anticipation for conflicts
baywet Jan 29, 2025
46e08d4
fix: tag reference proxy design pattern implementation
baywet Jan 29, 2025
e147e72
chore: removes unused test files
baywet Jan 29, 2025
e3c80a3
chore: cleans up temporary interface structure for references migration
baywet Jan 29, 2025
e4c14a4
fix: adds generic shallow copy method to avoid inadvertent conversion…
baywet Jan 29, 2025
d87375d
fix: last reference to copy constructor
baywet Jan 30, 2025
4ea87ef
fix: shallow copy for callback
baywet Jan 30, 2025
9bc3044
fix: shallow copy for example
baywet Jan 30, 2025
ce93aa7
fix: aligns reference copy constructors
baywet Jan 30, 2025
2a42c36
fix: switches header to shallow copy
baywet Jan 30, 2025
9af6f30
fix: shallow copy for parameter link path item and request body
baywet Jan 30, 2025
7ac149c
fix: tag, response, and security scheme shallow copy
baywet Jan 30, 2025
227d99d
fix: missing defensive programming in copy constructors
baywet Jan 30, 2025
019eb99
fix: missing null prop operator on parameter reference
baywet Jan 30, 2025
14750dc
fix: allow registration of component references
baywet Jan 30, 2025
e57d049
Merge pull request #2106 from microsoft/fix/schema-reference
baywet Jan 31, 2025
5071753
Merge pull request #2107 from microsoft/fix/security-scheme-reference
andrueastman Jan 31, 2025
c1f6733
Merge pull request #2109 from microsoft/fix/tag-reference
andrueastman Jan 31, 2025
5a27a3e
Merge remote-tracking branch 'origin/dev' into chore/string-comparisons
Jan 31, 2025
c637cc4
Merge pull request #2108 from microsoft/chore/string-comparisons
baywet Jan 31, 2025
32a5ec5
Merge branch 'dev' into fix/references-cleanup
baywet Jan 31, 2025
ac05342
fix: a bug where 3.0 downcast of type null would not work
baywet Jan 31, 2025
a5023d6
fix: null reference check
baywet Jan 31, 2025
121bb48
chore: formatting
baywet Jan 31, 2025
920a51a
fix: 3.0 serialization when type is set to null
baywet Jan 31, 2025
3b3d0e6
fix: do not emit a type array in 3.1 when unnecessary
baywet Jan 31, 2025
e09fb38
chore: simplifies the filter now that null reference exp are not an i…
baywet Jan 31, 2025
b5f68c9
Merge pull request #2111 from microsoft/fix/references-cleanup
baywet Feb 3, 2025
081e251
fix: null flag comparison
baywet Feb 3, 2025
306cd32
chore: code linting
baywet Feb 3, 2025
a46e857
fix: do not copy host document as it negatively impact performance
baywet Feb 3, 2025
ea0a415
ci: adds release please configuration
baywet Feb 3, 2025
801b968
ci: updates the ADO pipeline to match release please configuration
baywet Feb 3, 2025
974ab44
Merge branch 'dev' into fix/nullable-down-cast-3-0
baywet Feb 3, 2025
4d9c17b
fix: removes nullable property that shouldn't be part of dom
baywet Feb 3, 2025
2f171a3
fix: multiple unit test failures
baywet Feb 3, 2025
9e1cd20
Merge pull request #2114 from microsoft/ci/release-please
baywet Feb 4, 2025
1043e4e
Merge pull request #2113 from microsoft/fix/do-not-copy-document
baywet Feb 4, 2025
6b636d5
Merge pull request #2112 from microsoft/fix/nullable-down-cast-3-0
baywet Feb 4, 2025
4821b92
Merge pull request #2117 from microsoft/fix/no-more-nullable-property
andrueastman Feb 4, 2025
a946952
Remove dependency on CurrentCulture in tests
dldl-cmd Feb 4, 2025
f3a601b
Merge pull request #2118 from dldl-cmd/fix_test_not_independent_of_ma…
baywet Feb 4, 2025
fda05d4
fix: makes reference fields immutable
baywet Feb 4, 2025
89881fd
fix: makes target field read only
baywet Feb 4, 2025
92877e0
docs: adds considerations for why the target is readonly
baywet Feb 4, 2025
9cd7aae
fix: removes unused parameters
baywet Feb 4, 2025
a182f44
fix: makes reference of holder immutable
baywet Feb 4, 2025
ee6fae2
chore: linting
baywet Feb 4, 2025
317ad10
chore: code linting
baywet Feb 4, 2025
754f763
feat: makes document optional
baywet Feb 4, 2025
8ad773e
chore: code linting
baywet Feb 4, 2025
be3c552
chore: code linting
baywet Feb 4, 2025
e0aba68
chore: code linting
baywet Feb 4, 2025
4f99ad4
chore(deps): bump Verify.Xunit from 28.9.0 to 28.10.1
dependabot[bot] Feb 4, 2025
5b0c504
Merge pull request #2122 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Feb 4, 2025
de9d979
Merge pull request #2120 from microsoft/fix/removes-unused-parameter
baywet Feb 5, 2025
878dd08
Merge pull request #2121 from microsoft/fix/immutable-reference
baywet Feb 5, 2025
bd9f810
Support non-standard MIME type during format inference
MaggieKimani1 Feb 5, 2025
3f46ebf
Remove unnecessary format param; clean up extra semi-colon
MaggieKimani1 Feb 5, 2025
d5517ad
Use ArgumentNullException.ThrowIfNull instead of exliplicitly throwin…
MaggieKimani1 Feb 5, 2025
711b3d1
Update src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs
baywet Feb 5, 2025
50ddca2
Merge pull request #2124 from microsoft/fix/loading-exception
baywet Feb 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 7 additions & 12 deletions .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ trigger:
- main
- dev
- support/v1
tags:
include:
- 'v*'
pr:
branches:
include:
Expand Down Expand Up @@ -194,7 +197,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 +308,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 .config/1espt/PipelineAutobaseliningConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ pipelines:
lastModifiedDate: 2024-09-13
armory:
lastModifiedDate: 2024-09-13
binary:
credscan:
lastModifiedDate: 2025-01-27
binskim:
lastModifiedDate: 2025-01-27
spotbugs:
lastModifiedDate: 2025-01-27
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/auto-merge-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.2.0
uses: dependabot/fetch-metadata@v2.3.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ jobs:
id: getversion
- name: Push to registry - Nightly
if: ${{ github.ref == 'refs/heads/dev' }}
uses: docker/build-push-action@v6.12.0
uses: docker/build-push-action@v6.13.0
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly
- name: Push to registry - Release
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/support/v1' }}
uses: docker/build-push-action@v6.12.0
uses: docker/build-push-action@v6.13.0
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }}
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-preview5"
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

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.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageProjectUrl>https://github.com/Microsoft/OpenAPI.NET</PackageProjectUrl>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
<Version>2.0.0-preview5</Version>
</PropertyGroup>
<!-- https://github.com/clairernovotny/DeterministicBuilds#deterministic-builds -->
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
Expand Down
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"
}
67 changes: 28 additions & 39 deletions src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Humanizer.Inflections;
using Microsoft.OpenApi.Hidi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models.Interfaces;
using Microsoft.OpenApi.Services;

namespace Microsoft.OpenApi.Hidi.Formatters
Expand All @@ -15,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 @@ -41,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 All @@ -50,7 +51,7 @@ public override void Visit(OpenApiSchema schema)
base.Visit(schema);
}

public override void Visit(OpenApiPathItem pathItem)
public override void Visit(IOpenApiPathItem pathItem)
{
if (pathItem.Operations.TryGetValue(OperationType.Put, out var value) &&
value.OperationId != null)
Expand All @@ -69,24 +70,24 @@ public override void Visit(OpenApiOperation operation)

var operationId = operation.OperationId;
var operationTypeExtension = operation.Extensions?.GetExtension("x-ms-docs-operation-type");
if (operationTypeExtension.IsEquals("function"))
operation.Parameters = ResolveFunctionParameters(operation.Parameters ?? new List<OpenApiParameter>());
if (operationTypeExtension.IsEquals("function") && operation.Parameters is { Count :> 0})
ResolveFunctionParameters(operation.Parameters);

// Order matters. Resolve operationId.
operationId = RemoveHashSuffix(operationId);
if (operationTypeExtension.IsEquals("action") || operationTypeExtension.IsEquals("function"))
operationId = RemoveKeyTypeSegment(operationId, operation.Parameters ?? new List<OpenApiParameter>());
operationId = RemoveKeyTypeSegment(operationId, operation.Parameters ?? new List<IOpenApiParameter>());
operationId = SingularizeAndDeduplicateOperationId(operationId.SplitByChar('.'));
operationId = ResolveODataCastOperationId(operationId);
operationId = ResolveByRefOperationId(operationId);
// Verb segment resolution should always be last. user.get -> user_Get
operationId = ResolveVerbSegmentInOpertationId(operationId);
operationId = ResolveVerbSegmentInOperationId(operationId);

operation.OperationId = operationId;
base.Visit(operation);
}

private static string ResolveVerbSegmentInOpertationId(string operationId)
private static string ResolveVerbSegmentInOperationId(string operationId)
{
var charPos = operationId.LastIndexOf('.', operationId.Length - 1);
if (operationId.Contains('_', StringComparison.OrdinalIgnoreCase) || charPos < 0)
Expand Down Expand Up @@ -143,7 +144,7 @@ private static string RemoveHashSuffix(string operationId)
return s_hashSuffixRegex.Match(operationId).Value;
}

private static string RemoveKeyTypeSegment(string operationId, IList<OpenApiParameter> parameters)
private static string RemoveKeyTypeSegment(string operationId, IList<IOpenApiParameter> parameters)
{
var segments = operationId.SplitByChar('.');
foreach (var parameter in parameters)
Expand All @@ -157,30 +158,29 @@ private static string RemoveKeyTypeSegment(string operationId, IList<OpenApiPara
return string.Join('.', segments);
}

private static IList<OpenApiParameter> ResolveFunctionParameters(IList<OpenApiParameter> parameters)
private static void ResolveFunctionParameters(IList<IOpenApiParameter> parameters)
{
foreach (var parameter in parameters.Where(static p => p.Content?.Any() ?? false))
foreach (var parameter in parameters.OfType<OpenApiParameter>().Where(static p => p.Content?.Any() ?? false))
{
// 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
}
};
}
return parameters;
}

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
Loading
Loading