question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

If two response codes have different Content-Type, portman generates wrong test

See original GitHub issue

When having two different response codes (200 and a 400 for example) return different type of Content-Type, the generated test will assign to both the latest defined Content-Type

To Reproduce:

Using the following OpenAPI definition

openapi: 3.0.0
servers: 
  - url: "http://localhost:8080" 
info:
  title: Sample API
  description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
  version: 0.1.9
paths:
  /users:
    post:
      summary: "Example"
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
      responses:
        "201":
          description: "API deployed"
          content:
            text/plain:
              schema:
                type: string
        "400":
          description: "The content of the API is malformed"
          content:
            application/json:
              schema:
                properties: 
                  message:
                    type: string

1 - Run a mock server with prism

prism mock openapi.yaml -p 8080

2 - Run portman to generate tests

portman -l openapi.yaml

3 - Check that test “Schema is Valid” for response code 200 asserts for application/json when it should assert for text/plain, as stated in the openapi definition:

// file tmp/converted/simpleApi.json
...
 "// Response Validation\nconst schema = {\"type\":\"string\"}\n\n// Validate if response matches JSON schema \npm.test(\"[POST]::/users - Schema is valid\", function() {\n    pm.response.to.have.jsonSchema(schema,{unknownFormats: [\"int32\", \"int64\", \"float\", \"double\"]});\n});\n"
...

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
aabedrabacommented, Sep 20, 2022

@thim81 thank you SO much!!!

1reaction
thim81commented, Sep 8, 2022

hi @aabedraba,

Thanks for providing the helpful video. I’ll try to look into the issue. My 1st quest will be to find out why the error is thrown, since the the validation error seems to come from the openapi-to-postman conversion step.

Read more comments on GitHub >

github_iconTop Results From Across the Web

multiple content types in openAPI spec result in SyntaxError in ...
When contract tests are generated, there is a SyntaxError: ... that portman only supports json responses and do not generate tests for other...
Read more >
How do I generate a specific HTTP response code using a ...
Currently I only get 2-3 HTTP status response codes, 200 OK for success and 400 (bad request if I don't have the body...
Read more >
Portman CLI 1.0 - Better API testing - Apideck Blog
Portman leverages your static OpenAPI specs, with all its defined API request/response properties, to power your Postman collection and test suite.
Read more >
@apideck/portman - npm
Let Portman do all the work and inject contract & variation tests with a minimum of configuration. Customize the Postman requests & variables ......
Read more >
Postman Snippets to Assert API response status codes
Check the Status Code; Check the content type; Make sure the body is valid JSON. Check other conditions based on the state of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found