If two response codes have different Content-Type, portman generates wrong test
See original GitHub issueWhen 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:
- Created a year ago
- Comments:10
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@thim81 thank you SO much!!!
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.