Open nandhinik opened 5 years ago
Thanks for the issue! We fixed a bunch of issues in https://github.com/apiaryio/dredd/pull/1351. Could you please verify that this is still relevant with the latest Dredd version? If so, I’ll re-open the issue. Thank you 🙏
Had the same issue but I think i fixed it by using type: object
in your model definition when defining an object.
@honzajavorek seems to me like this is still an issue. I hope it is ok if I continue on this issue.
I get the same result with the following:
To Reproduce
const Dredd = require('dredd');
let configuration = {
options: {
endpoint: 'http://127.0.0.1:3000'
},
loglevel: 'debug',
path: ['animals.yaml'],
};
let dredd = new Dredd(configuration);
dredd.run((err) => {
if (err) {
console.error('Encountered problems!');
console.error(err);
process.exit(1);
}
})
animals.yaml:
openapi: "3.0.0"
info:
version: 1.0.0
title: Animals
paths:
/animals:
post:
summary: Create animal
requestBody:
content:
application/vnd.api+json:
schema:
#type: object
properties:
data:
$ref: '#/components/schemas/AnimalRequest'
responses:
'201':
description: Animal created
content:
application/vnd.api+json:
schema:
properties:
data:
$ref: "#/components/schemas/Animal"
components:
schemas:
AnimalRequest:
#type: object
properties:
type:
description: Resource type
enum:
- animals
type: string
attributes:
#type: object
properties:
name:
description: 'The name of the animal'
type: string
example: 'Pluto'
Animal:
properties:
type:
description: Resource type
enum:
- animals
type: string
id:
description: Unique ID of the animal
type: string
example: '123e4567-e89b-12d3-a456-426655440000'
attributes:
properties:
name:
description: 'The name of the animal'
type: string
example: 'Pluto'
will return:
...
2019-05-21T13:40:20.746Z - debug: Could not stringify:
request:
method: POST
uri: /animals
headers:
Content-Type: application/vnd.api+json
User-Agent: Dredd/11.1.0 (Linux 4.15.0-50-generic; x64)
body:
expected:
headers:
...
Expected behavior
If I uncomment line 14, 32 and 40 (#type: object
) in animals.yaml
a body is correctly returned.
...
request:
method: POST
uri: /animals
headers:
Content-Type: application/vnd.api+json
User-Agent: Dredd/11.1.0 (Linux 4.15.0-50-generic; x64)
body:
{
"data": {
"type": "animals",
"attributes": {
"name": "Pluto"
}
}
}
expected:
headers:
Content-Type: application/vnd.api+json
...
Seems that Dredd really wants us to specify type: object
. I could be wrong, but I thought you don't have to specify type: object
according to the specification. Perhaps Dredd should assume an object if nothing else is specified?
What is in your dredd.yml?
No dredd.yml
.
What's your dredd --version output?
dredd v11.1.0 (Linux 4.15.0-50-generic; x64)
Thanks folks, we'll investigate this.
Hi All!
It seems there was some issue in parsing request body in OAPI v3 and installing dependent libraries solved this issue. Please let me know if this change makes sense and update the source code accordingly. Thanks!
Please refer below for code changes:
@nandhinik Dredd should already have the latest Dredd Transactions, which already has the latest OAS3 adapter: https://github.com/apiaryio/dredd/blob/master/package.json#L43 Install the latest Dredd to see whether it solves your problem. According to reports here though it seems this particular problem wasn't fixed yet by our changes.
Dredd sends empty request body for POST api call with requestBody for Open API 3.0.0 and 3.0.2 versions where as it works for Open API 2.0
To Reproduce Run dredd with the following OpenAPI v3 specification (fragment):
Expected behavior Request body should be present(not empty)
What is in your dredd.yml? Not using it
dredd Command dredd petstore.yml http://petstore.swagger.io/api --language=python --hookfiles=p_hooks.py --loglevel=debug
What's your dredd --version output? dredd v9.0.4 (Darwin 17.7.0; x64)
Does dredd --loglevel=debug uncover something? I added print statement to print request body in hooks file @hooks.before_each
Can you send us failing test in a Pull Request? No