# Should text/plain work with (Generator) contract test collection

**URL:** <https://community.postman.com/t/should-text-plain-work-with-generator-contract-test-collection/39046>\
**Category:** Help Hub\
**Tags:** test, contract, generator\
**Created:** [September 12, 2022, 10:03am UTC](https://community.postman.com/t/should-text-plain-work-with-generator-contract-test-collection/39046 "2022-09-12T10:03:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcel.tc](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@marcel.tc](https://community.postman.com/u/marcel.tc)\
**Post date:** [September 12, 2022, 10:03am UTC](https://community.postman.com/t/should-text-plain-work-with-generator-contract-test-collection/39046/1 "2022-09-12T10:03:23Z")

</div>

After seeing the Space Camp Video [API Contract Testing | Postman Space Camp - YouTube](https://www.youtube.com/watch?v=INJla2N2iZU) I was very interested to try the [Postman](https://www.postman.com/postman/workspace/contract-test-generator/overview) collection from @allenheltondev

So I started to write an OpenApi Spec for a project of ours. I tried to keep it simple and started with our /health endpoint which just returns a string. But I can’t get it to work.  
When I change the endpoint and Spec to return an object in application/json it works just fine.  
So the question is: **Should this collection work with a text/plain response?**

_Details_:  
This is a spec that is working:

```auto
paths:
  /health:
    get:
      summary: "GET health"
      responses:
        "200":
          description: "OK"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Uuid'
components:
  schemas:
    Uuid:
      type: object
      properties:
        uuid:
          type: string
          description: a randomly generated uuid
          example: 'b343a68d-d10b-427c-b4d5-7e8f231c4920'
  

```

But when I put it like this for the simple String response:

```auto
paths:
  /health:
    get:
      summary: "GET health"
      responses:
        "200":
          description: "OK"
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/Uuid'
components:
  schemas:
    Uuid:
      type: string
      description: a randomly generated uuid
      example: 'b343a68d-d10b-427c-b4d5-7e8f231c4920'

```

The ‘Test Request’ request then fails with  
**GET - /health - No Request Body - SUCCESS: true - Has expected response body schema | TypeError: Cannot convert undefined or null to object**

A little console.log magic shows that expectedResponse is only

```auto
{statusCode: 200}

```

which leads the code to the line

```auto
return (Object.keys(responseSchema).length == 0);

```

where responseSchema is undefined

On an application/json response the expectedResponse variable looks like

```auto
{statusCode: 200, $ref: "#/components/schemas/Uuid"}

```

with this ‘$ref’ property the code takes completely other turns.

So to summarise the questions:

1. Should the collection work with text/plain
2. If yes what do I need to change in my openApi spec

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [September 12, 2022, 12:33pm UTC](https://community.postman.com/t/should-text-plain-work-with-generator-contract-test-collection/39046/2 "2022-09-12T12:33:51Z")

</div>

It does not currently support that response type. But you’re welcome to enhance it to do so.

> **[GitHub - allenheltondev/postman-contract-test-generator: Postman collection...](https://github.com/allenheltondev/postman-contract-test-generator)**
>
> Postman collection and environment that will take an Open API Spec, validate component adherence, generate contract tests, and execute them. - GitHub - allenheltondev/postman-contract-test-generato...

---

<div class="post-metadata">

**Author:** ![marcel.tc](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@marcel.tc](https://community.postman.com/u/marcel.tc)\
**Post date:** [September 12, 2022, 1:42pm UTC](https://community.postman.com/t/should-text-plain-work-with-generator-contract-test-collection/39046/3 "2022-09-12T13:42:39Z")

</div>

Thanks for your reply. Good to know!  
Will have to dive a little deeper into the whole OpenAPI stuff first. Still need to sell this to my colleagues.  
After that I will try to figure out, if I can contribute to your repo!
