Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

How to use blueprint for resource creates when id is provisioned by server? #96

Closed
gobengo opened this issue Sep 4, 2014 · 8 comments
Closed

Comments

@gobengo
Copy link

gobengo commented Sep 4, 2014

Hey, I have the following in my blueprint.

I'm trying to 'create a new app'. When I do this, the server provisions and id and includes it in the response body JSON. It also includes a location header in the response which is a relative URL to the newly created app resource. This location header should be considered opaque, but happens to be using the newly provisioned id.

### Create New App [POST]

Create a new app

Requires authorization to create apps. App creator is the subject of the access
token.

+ Request

    + Headers

            Content-Type: application/json

    + Body

            {
                "name": "example-map",
                "version": "0.0.0"
            }

+ Request

    + Headers

            Content-Type: application/json

    + Body

            {
                "version": "0.0.0"
                "elements": [{
                    "component": {
                        "name": "streamhub-wall"
                    }
                }]
            }

+ Response 201

    + Headers

            location: /apps/5408ddd782f3910000000004

    + Body

            {
                "id": "5408ddbb82f3910000000002",
                "url": "/apps/5408ddbb82f3910000000002"
            }

Whenever I run dredd against this, it fails because the location header in practice is some id other than what's in the blueprint.

Is there any way to author my blueprint to ensure that the location header is present in the response, but not fail the thing just because it's a new unique id?

fail: headers: Value of the ‘location’ must be /apps/5408ddd782f3910000000004.

request: 
body: 
{
  "name": "example-map",
  "version": "0.0.0"
}
headers: 
    Content-Type: application/json
    User-Agent: Dredd/0.3.9 (Darwin 13.3.0; x64)
    Content-Length: 54

uri: /apps/
method: POST


expected: 
headers: 
    location: /apps/5408ddd782f3910000000004

body: 
{
    "id": "5408ddbb82f3910000000002",
    "url": "/apps/5408ddbb82f3910000000002"
}

statusCode: 201


actual: 
statusCode: 201
headers: 
    access-control-allow-origin: *
    location: /apps/5408e0ec82f3910000000012
    content-type: application/json; charset=utf-8
    content-length: 81
    date: Thu, 04 Sep 2014 22:00:12 GMT
    connection: keep-alive

body: 
{
  "id": "5408e0ec82f3910000000012",
  "url": "/apps/5408e0ec82f3910000000012"
}
@netmilk
Copy link
Contributor

netmilk commented Sep 8, 2014

HI, this will be solve in next release of Dredd respectively Gavel which is used in Dredd for validating HTTP messages. Only value of content-type headers will be validated. Other header values will not be validated, so your location header will pass.

@gobengo
Copy link
Author

gobengo commented Sep 12, 2014

@netmilk Would that help at all with trying to do a flow where I create a resource, the server provisions an id and responds with it, and another endpoint is exposed at a path that needs that dynamic ID passed to it?

@ghost
Copy link

ghost commented Oct 7, 2014

+1 to this feature. It'll very useful.

when is the next version scheduled?

@surtich
Copy link

surtich commented Oct 7, 2014

+1 I would like this too. Other similar things can be solved with hooks. But I think hooks are not useful in this case.

@netmilk
Copy link
Contributor

netmilk commented Oct 11, 2014

Hi, this can be solved by creating response stash in hooks and replacing expected header value in the transaction before its execution.

@netmilk
Copy link
Contributor

netmilk commented Jan 16, 2015

Reopening after discussion in #108

@netmilk netmilk reopened this Jan 16, 2015
@stephanheinze
Copy link

👍

@netmilk
Copy link
Contributor

netmilk commented Mar 23, 2015

Hi,

we recently changed the way how we validate headers in Gavel, please refer to: apiaryio/gavel.js#53. Only values of content-negotiation significant headers are treated as constants. This functionality is in Dredd > 0.4.8.

For example: value of the Location header can be different in real response then given in blueprint.

This should fix this issue when you rely on data provisioned by server and you have no way how to retrieve it and modify expectation in before hooks.

Adam

@netmilk netmilk closed this as completed Mar 23, 2015
artem-zakharchenko pushed a commit that referenced this issue Oct 9, 2019
…things

Consolidate (de)serialization of refract and refactor tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants