Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: OpenApiSpecGeneratorPlugin throws error when processing responses from CRUD API or mocked response plugins #687

Closed
garrytrinder opened this issue May 3, 2024 · 0 comments · Fixed by #691
Assignees
Labels
bug Something isn't working work in progress

Comments

@garrytrinder
Copy link
Contributor

Description

When using the OpenApiSpecGeneratorPlugin to record requests that are responded to using the CRUD API or mocked response plugins an error is thrown.

Expected behaviour

OpenAPI spec is generated

Actual behaviour

Error is thrown

Error processing request GET
http://api.contoso.com/products
System.Exception: Response body is not read yet. Use SessionEventArgs.GetResponseBody() or SessionEventArgs.GetResponseBodyAsString() method to read the response body.     
   at Titanium.Web.Proxy.Http.Response.EnsureBodyAvailable(Boolean throwWhenNotReadYet)
   at Titanium.Web.Proxy.Http.RequestResponseBase.get_Body()
   at Titanium.Web.Proxy.Http.RequestResponseBase.get_BodyString()
   at Microsoft.DevProxy.Plugins.RequestLogs.OpenApiSpecGeneratorPlugin.SetResponseFromSession(OpenApiOperation operation, Response response)
   at Microsoft.DevProxy.Plugins.RequestLogs.OpenApiSpecGeneratorPlugin.GetOpenApiPathItem(SessionEventArgs session)
   at Microsoft.DevProxy.Plugins.RequestLogs.OpenApiSpecGeneratorPlugin.AfterRecordingStop(Object sender, RecordingArgs e)

Steps to reproduce

  • Create config file that uses OpenApiSpecGeneratorPlugin and either the MockResponsePlugin or CRUDApiPlugin
  • Start devproxy using --config-file option and --record flag
  • Send request to API (request is output in console as mocked)
  • Stop recording

Dev Proxy Version

0.17.1

Operating system (environment)

Windows

Shell

PowerShell

Configuration file

{
    "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.17.1/rc.schema.json",
    "plugins": [
        {
         "name": "MockResponsePlugin",
         "enabled": true,
         "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
         "configSection": "mocksPlugin"
        },
        {
            "name": "OpenApiSpecGeneratorPlugin",
            "enabled": true,
            "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
        }
    ],
    "urlsToWatch": [
        "http://api.contoso.com/*"
    ],
    "mocksPlugin": {
        "mocksFile": "mocks.json"
    }
}

Additional Info

{
    "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.17.1/mockresponseplugin.schema.json",
    "mocks": [
        {
            "request": {
                "method": "GET",
                "url": "http://api.contoso.com/products"
            },
            "response": {
                "body": [
                    {
                        "productCode": "CTOQAD",
                        "productName": "Contoso Quad",
                        "description": "A state-of-the-art drone designed for the enterprise market. With its advanced flight controls and high payload capacity, it’s perfect for a variety of commercial applications. Its robust design ensures reliable performance in challenging conditions.",
                        "targetMarket": "Enterprise",
                        "priceUSD": 5000
                    },
                    {
                        "productCode": "EGLAIR",
                        "productName": "Eagle Air",
                        "description": "A high-performance drone built for enterprise use. It offers exceptional flight time and range, making it ideal for large-scale operations. Its advanced camera and sensor systems provide high-quality aerial data.",
                        "targetMarket": "Enterprise",
                        "priceUSD": 6000
                    },
                    {
                        "productCode": "GMBLCS",
                        "productName": "Gimbal Case",
                        "description": "Durable and lightweight case designed to protect your drone during transport. Compatible with a variety of drone models, it features a custom foam interior to ensure a secure fit.",
                        "targetMarket": "Consumer",
                        "priceUSD": 100
                    },
                    {
                        "productCode": "MRK8DR",
                        "productName": "Mark8",
                        "description": "Consumer-grade drone that combines ease of use with advanced features. It offers stable flight, high-quality video capture, and a range of intelligent flight modes.",
                        "targetMarket": "Consumer",
                        "priceUSD": 800
                    },
                    {
                        "productCode": "MRK8CR",
                        "productName": "Mark8 Controller",
                        "description": "Designed to provide precise control over your Mark8 drone. Its ergonomic design and intuitive controls make it easy to pilot your drone, while its built-in display keeps you informed about your drone’s status.",
                        "targetMarket": "Consumer",
                        "priceUSD": 150
                    }
                ]
            }
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working work in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants