mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.54k stars 1.06k forks source link

Spec and typescript missing request_response response object schema #1368

Closed simontankersley closed 1 year ago

simontankersley commented 2 years ago

Hi there, firstly thank you for such a great product.

I think I've found an issue. I see the resolution of this past issue was support for a retrieve type of "request_response". I think perhaps the openapi schema update to the responses and schema sections were overlooked. I also note that the return type of MockServerClient.retrieveRecordedRequestsAndResponses in the typescript client is Promise<Expectation[]> not something like Promise<RequestResponse[]> (and this could be related to the missing open api spec changes)

simontankersley commented 1 year ago

Thanks for the fix @jamesdbloom. The return type of MockServerClient.retrieveRecordedRequestsAndResponses in the typescript client is now Promise<HttpRequestAndHttpResponse[]>:

    retrieveRecordedRequestsAndResponses(pathOrRequestDefinition: PathOrRequestDefinition): Promise<HttpRequestAndHttpResponse[]>;

However in server and client 5.14.0 when comparing the typescript schema of HttpRequestAndHttpResponse against the javascript object returned there is a difference for some reason.

The typescript schema of HttpRequestAndHttpResponse is:

export type HttpRequestAndHttpResponse = {
    httpRequest?: HttpRequest[];
    httpResponse?: HttpResponse[];
    timestamp?: string;
};

export interface HttpRequest {
  headers?: KeyToMultiValue;
...
}

export type KeyToMultiValue =
  | { name?: string; values?: string[] }[]
  | { keyMatchStyle?: "MATCHING_KEY" | "SUB_SET"; [key: string]: any };

However the HttpRequestAndHttpResponse objects in the returned in the HttpRequestAndHttpResponse[] array have structure:

{
  httpRequest: {
    headers: {
      'header1': ['value1']
      'header2': ['value2']
      ...
    }
  }
}

not:

{
  httpRequest: [
    {
      headers: [
        {
          name: 'header1',
          value: ['value1']
        },
        {
          name: 'header2',
          value: ['value2']
        }
        ...
      ]
    }
  ]
}

I've worked around the mis match with code:

const headers = (requestAndResponse.httpRequest as any).headers
const header1values = headers['header1']