WithMappingFromOpenApiFile fails with exception when example item present in text-plain response in OAS contract #679

Closed
opened 2025-12-29 08:32:27 +01:00 by adam · 4 comments
Owner

Originally created by @TomRom27 on GitHub (Apr 4, 2025).

Originally assigned to: @StefH on GitHub.

Description

OpenAPI content response can be of different types, plain text amongst others, like below:

        "responses": {
          "200": {
            "description": "Ok: The request has succeeded",
            "content": {
              **"text/plain; charset=utf-8": {**
                "schema": {
                  "type": "string",
                  **"example": "This is an example for 200"**
                }
              }
            }
          }
        } 

Microsoft's OpenApiStreamReader imports it without any problem and thus we can see example item in this case is represented as simple string

Image

But WithMappingFromOpenApiFile fails and raises exception:
"Error reading JObject from JsonReader. Current JsonReader item is not an object: String. Path '', line 1, position 28."

Looks like inside MapOperationToMappingModel it fails to handle the responseExample - if it is simple string.

Expected behavior

OAS contract with example item for text-plain can be used for mappings.

Test to reproduce

  • run WithMappingFromOpenApiFile on a file with example in response of plain-text type - use attached file.

oas-content-example.json

Originally created by @TomRom27 on GitHub (Apr 4, 2025). Originally assigned to: @StefH on GitHub. ### Description OpenAPI content response can be of different types, plain text amongst others, like below: ``` yml "responses": { "200": { "description": "Ok: The request has succeeded", "content": { **"text/plain; charset=utf-8": {** "schema": { "type": "string", **"example": "This is an example for 200"** } } } } } ``` Microsoft's OpenApiStreamReader imports it without any problem and thus we can see example item in this case is represented as simple string ![Image](https://github.com/user-attachments/assets/fc9bc86d-d03a-44bc-9c37-27ce11bb6bc3) But WithMappingFromOpenApiFile fails and raises exception: "Error reading JObject from JsonReader. Current JsonReader item is not an object: String. Path '', line 1, position 28." Looks like inside MapOperationToMappingModel it fails to handle the responseExample - if it is simple string. ### Expected behavior OAS contract with example item for text-plain can be used for mappings. ### Test to reproduce - run WithMappingFromOpenApiFile on a file with example in response of plain-text type - use attached file. [oas-content-example.json](https://github.com/user-attachments/files/19601002/oas-content-example.json) ### Other related info
adam closed this issue 2025-12-29 08:32:27 +01:00
Author
Owner

@StefH commented on GitHub (May 13, 2025):

https://github.com/wiremock/WireMock.Net/pull/1294

@StefH commented on GitHub (May 13, 2025): https://github.com/wiremock/WireMock.Net/pull/1294
Author
Owner

@StefH commented on GitHub (May 13, 2025):

@TomRom27
Can you retry with latest version?

@StefH commented on GitHub (May 13, 2025): @TomRom27 Can you retry with latest version?
Author
Owner

@TomRom27 commented on GitHub (May 14, 2025):

Sure I will.
Thx a lot!

@TomRom27 commented on GitHub (May 14, 2025): Sure I will. Thx a lot!
Author
Owner

@TomRom27 commented on GitHub (May 14, 2025):

I checked and it works.
Thx a lot!

@TomRom27 commented on GitHub (May 14, 2025): I checked and it works. Thx a lot!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#679