blue_bird icon indicating copy to clipboard operation
blue_bird copied to clipboard

Including request body XML in output documentation

Open DavidOliver opened this issue 7 years ago • 4 comments

My test:

  test "creates support_request and returns support_request ID when data is valid", %{conn: conn} do
    body = ~s(<?xml version="1.0" encoding="utf-8"?>
      <data>
        <SamplerID>#{@create_attrs.sampler_id}</SamplerID>
        <SupportRequest>
          <ContactName>#{@create_attrs.contact_name}</ContactName>
          <ContactEmail>#{@create_attrs.contact_email}</ContactEmail>
          <Title>#{@create_attrs.title}</Title>
          <Details>#{@create_attrs.details}</Details>
        </SupportRequest>
      </data>
    )
    conn = conn
    |> put_req_header("user-agent", @create_attrs.user_agent)
    |> put_req_header("content-type", "application/xml")
    |> post(support_request_path(conn, :create), body)
    |> BlueBird.ConnLogger.save()

    # assert that text the length of a UUID forms the response body
    assert text_response(conn, 200) |> String.length == 36
  end

The resultant Body in the Request in the output documentation:

{"aspect":"body_params"}

Is it possible to have the request body XML included? Thanks.

DavidOliver avatar Jun 23 '17 10:06 DavidOliver

Hi David,

right now, BlueBird is only able to handle json and plain text bodies correctly. We're going to add support for other content types in the future, but I can't give you a time frame yet.

woylie avatar Jun 23 '17 10:06 woylie

Okay - thanks for the info.

DavidOliver avatar Jun 23 '17 10:06 DavidOliver

I'm thinking about getting round it for now by manually putting the request body XML in the description; see screenshot:

screenshot from 2017-06-24 15-53-27

The main issue with this workaround is that the incorrect request body is present in the right-hand column. Any ideas on hiding it? If this isn't possible I may switch to writing out the API Blueprint "design" manually for projects which use XML, but I thought I'd ask here first. :) Many thanks.

DavidOliver avatar Jun 24 '17 14:06 DavidOliver

I don't have a quick fix for this. What we could do in a future version is to check the request content-type header before adding it to the documentation.

One difficulty in general is that you can only read the request body from the conn once. So as soon as a plug reads the body, we can't access it with BlueBird anymore. We'll have to put in some thought to figure out how to handle request bodies in a nice way.

woylie avatar Jun 24 '17 15:06 woylie