From a3d05417d17f18462e755a4f5691142cbcf210df Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 21 Jan 2025 10:14:35 +0300 Subject: [PATCH 1/2] pass host document for reference resolution --- .../Reader/V3/OpenApiRequestBodyDeserializer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiRequestBodyDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiRequestBodyDeserializer.cs index 435b576e1..75cdb8fe3 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiRequestBodyDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiRequestBodyDeserializer.cs @@ -52,7 +52,7 @@ public static OpenApiRequestBody LoadRequestBody(ParseNode node, OpenApiDocument var requestBody = new OpenApiRequestBody(); foreach (var property in mapNode) { - property.ParseField(requestBody, _requestBodyFixedFields, _requestBodyPatternFields); + property.ParseField(requestBody, _requestBodyFixedFields, _requestBodyPatternFields, hostDocument); } return requestBody; From c39fa84b4d43f9a7ce053ad5cb351407be5d7fc6 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 21 Jan 2025 10:14:58 +0300 Subject: [PATCH 2/2] Add test --- .../V3Tests/OpenApiDocumentTests.cs | 12 ++++ .../docWithExampleReferences.yaml | 68 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/docWithExampleReferences.yaml diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs index 864bb5aaa..9ddadd239 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs @@ -1411,5 +1411,17 @@ public async Task ParseDocumentWithEmptyPathsSucceeds() var result = await OpenApiDocument.LoadAsync(System.IO.Path.Combine(SampleFolderPath, "docWithEmptyPaths.yaml")); result.Diagnostic.Errors.Should().BeEmpty(); } + + [Fact] + public async Task ParseDocumentWithExampleReferencesPasses() + { + // Act & Assert: Ensure no NullReferenceException is thrown + Func act = async () => + { + await OpenApiDocument.LoadAsync(System.IO.Path.Combine(SampleFolderPath, "docWithExampleReferences.yaml")); + }; + + await act.Should().NotThrowAsync(); + } } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/docWithExampleReferences.yaml b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/docWithExampleReferences.yaml new file mode 100644 index 000000000..da2708545 --- /dev/null +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/docWithExampleReferences.yaml @@ -0,0 +1,68 @@ +openapi: 3.0.3 +info: + version: 1.1.4 + title: GitHub v3 REST API + description: GitHub's v3 REST API. +paths: + /actions/hosted-runners/{hosted_runner_id}: + get: + summary: Get a GitHub-hosted runner for an organization + description: |- + Gets a GitHub-hosted runner configured in an organization. + OAuth app tokens and personal access tokens (classic) need the `manage_runners:org` scope to use this endpoint. + responses: + '200': + description: Response + content: + application/json: + schema: + "$ref": "#/components/schemas/actions-hosted-runner" + examples: + default: + "$ref": "#/components/examples/actions-hosted-runner" + /oidc/customization/sub: + get: + summary: Get the customization template for an OIDC subject claim for an organization + description: |- + Gets the customization template for an OpenID Connect (OIDC) subject claim. + OAuth app tokens and personal access tokens (classic) need the `read:org` scope to use this endpoint. + requestBody: + required: true + content: + application/json: + schema: + "$ref": "#/components/schemas/oidc-custom-sub" + examples: + default: + "$ref": "#/components/examples/oidc-custom-sub" + responses: + '200': + description: A JSON serialized template for OIDC subject claim customization + content: + application/json: + schema: + "$ref": "#/components/schemas/oidc-custom-sub" +components: + schemas: + actions-hosted-runner: + title: GitHub-hosted runner + type: object + oidc-custom-sub: + title: Actions OIDC Subject customization + description: Actions OIDC Subject customization + type: object + examples: + actions-hosted-runner: + value: + id: 5 + name: My hosted ubuntu runner + runner_group_id: 2 + platform: linux-x64 + oidc-custom-sub: + value: + include_claim_keys: + - repo + - context + + + \ No newline at end of file