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

Update dredd to support nullable attribute #283

Closed

Description

@obihann

Dredd should properly test against the new nullable attribute supported by MSON and drafter.

md
+ s1 (string, nullable)

json
{"s1":null}

I can help with this however I am not 100% sure if I need to make changes to drafter.js or protagonist?

Thanks.

Activity

  1. netmilk commented on Sep 29, 2015

    @netmilk
    Contributor

    Hi @obihann,

    you're right, this a Drafter issue. Drafter compiles JSON schema from MSON and this JSON schema is used for Gavel validation of server response. Since this feature will be introduced in Drafter it's only a matter of bumping Drafter version in Dredd to support it.

  2. obihann commented on Sep 29, 2015

    @obihann
    Author

    Awesome! @pksunkara when can can we expect a new release of drafter? I know nullable is in the master branch since I was so involved in that, but it seems that we need a new tag release so that Dredd can point specifically to that.

  3. pksunkara commented on Sep 29, 2015

    @pksunkara
    Contributor

    Unfortunately, we can't announce nullable support until apiaryio/drafter#121 is done. But other than that, we have a bit of work currently happening after which there will be a new drafter release.

  4. obihann commented on Sep 29, 2015

    @obihann
    Author

    @pksunkara thanks, I'll try to take a look at that tonight and help you guys out a bit.

    @netmilk I just want to verify all that is holding this up is in fact apiaryio/drafter, I ask this because I understood dredd uses apiaryio/drafter.js (which is being replaced by apiaryio/protagonist)?

  5. obihann commented on Sep 29, 2015

    @obihann
    Author

    I think I have my confusion figured out @netmilk... Dredd uses drafter.js which is a wrapper (?) for protagonist which uses drafter via a git module. Right?

  6. pksunkara commented on Sep 29, 2015

    @pksunkara
    Contributor

    Dredd uses drafter.js which uses protagonist 0.x. We need to move dredd to protagonist 1.x.

  7. obihann commented on Sep 29, 2015

    @obihann
    Author

    That makes perfect sense, thanks. I'm kind of afraid to ask but what is waiting on moving dredd to protagonist 1.x?

    Thanks.

  8. pksunkara commented on Sep 29, 2015

    @pksunkara
    Contributor

    I think @netmilk will be more suited to answer this.

  9. obihann commented on Sep 29, 2015

    @obihann
    Author

    Sounds good, thanks.

  10. obihann commented on Sep 30, 2015

    @obihann
    Author

    @netmilk I'm running into some difficulty right now testing an update to dredd so that it will use drafter.js and the latest (currently master branch) version of drafter. I have a feeling this may be because (as @pksunkara) dredd needs to use protagonist 1.x directly and eliminate the reference to drafter.js.

    My question is how complex or simple do you think that will be, and what are the blockers preventing it from happening?

    I have a high priority issue right now with the project I am on that we cannot properly test our API with dredd due to the null limitations, I've been working closly with @pksunkara to implement this on MSON, snowcrash, and drafter, now that that is close to complete dredd is the next focus of my attention. I can help out on this, I just need to know what the blockers are so I can tackle them.

  11. netmilk commented on Oct 2, 2015

    @netmilk
    Contributor

    Hi @obihann,

    Mainly, thank you very much for all your enthusiasm and and contributions but at this moment, updating to the latest protagonist won't solve your issue with nullable parameter. Drafter (not .js) used in the latest protagonist doesn't have feature parity with drafter.js (yes, .js) which supports JSON schema rendering from MSONs. Updating to the protagonist would cause complete disabling of validation of MSON structures in Dredd.

    @zdne confirmed the Blueprint team is working on support of JSON schema rendering in the Drafter (not .js) used in the latest protagonist and they are treating it as a priority.

    If this is a limitation for using Dredd in your actual project, I would propose some workaround in beforeAll hooks where you can modify the generated schema in the transaction object under the expected.body.schema property.

  12. obihann commented on Oct 2, 2015

    @obihann
    Author

    Hi @netmilk, thank you for your reply. Yes, this may be a limitation, so I will have to look into your suggested work around.

    Regarding protagonist, drafter, and drafter.js... Let me see if I fully understand this.

    Dredd (latest release) uses Drafter.js (latest release), which uses Protagonist (older 0.x release), which finally uses Dredd (older release again).

    The latest version of Protagonist (1.x) uses a newer version of Dredd (not the latest though), however this results in a different feature set than what Dredd.js (using 0.x Protagonist) provides? Because of this my attempts to migrate Dredd to Protagonist 1.x and eliminate Drafter.js is actually a very large task that will not solve my original issues.

    Adding all that together, I am seeing that the latest version of Drafter does have the features I need, and the scheduled 1.1.0 release of Drafter will also include 'nullable'. So this is a rough outline of what has to happen before Dredd can properly support nullable

    1. 1.1.0 release of Drafter
    2. Protagonist updated to 1.1.0 version of drafter
    3. Dredd updated to use the above mentioned release of Protagonist

    Does all that sound about right? Sorry, if I am way off.

    If I am actually correct, then I think I need to work with @zdne currently to get the 1.1.0 release of Drafter taken care of, and then Protagonist updated to use that. Then I can return to Dredd.

  13. pksunkara commented on Oct 5, 2015

    @pksunkara
    Contributor

    I think this is more of a correct outline.

    1. JSON Schema rendering support in Drafter
    2. 1.1.0 release of Drafter
    3. Protagonist updated to 1.1.0 version of drafter
    4. Dredd updated to use the above mentioned release of Protagonist
  14. obihann commented on Oct 5, 2015

    @obihann
    Author

    @pksunkara thanks. What is involved in #1 and how can I assist?

  15. justinabrahms commented on Nov 6, 2015

    @justinabrahms

    I'm having some difficulty with the workaround. Can someone validate that this is roughly what you guys were expecting?

    @hooks.before_all
    def make_moudle_price_nullable(transactions):
        for t in transactions:
            try:
                schema = json.loads(t['expected']['bodySchema'])
                schema['nullable'] = ['price_per_seat_cents']
                t['expected']['bodySchema'] = json.dumps(schema)
            except KeyError:
                pass

    It still fails with the error fail: body: At '/price_per_seat_cents' Invalid type: null (expected number). I'm using dredd @ 1.0.1. I've also tried making expected.bodySchema.price_per_seate_cents.type = 'number,nullable' and it didn't seem to work.

    You can find the offending code at https://github.com/mitodl/ccxcon/tree/project-skeleton The relevant files are apiary.apib and apiary_hooks.py in the root of the repository. Full failure below.

    Configuration dredd.yml found, ignoring other arguments.
    info: Using apiary reporter.
    warn: Apiary reporter environment variable APIARY_API_KEY or APIARY_API_NAME not defined.
    info: Beginning Dredd testing...
    Spawning `python` hooks handler
    Hook handler stdout: Starting Dredd Python hooks handler
    
    Hook handler stderr: apiary_hooks.py:1: RuntimeWarning: Parent module 'apiary_hooks' not found while handling absolute import
      import json
    apiary_hooks.py:2: RuntimeWarning: Parent module 'apiary_hooks' not found while handling absolute import
      import os
    apiary_hooks.py:4: RuntimeWarning: Parent module 'apiary_hooks' not found while handling absolute import
      import django
    apiary_hooks.py:5: RuntimeWarning: Parent module 'apiary_hooks' not found while handling absolute import
      import dredd_hooks as hooks
    apiary_hooks.py:10: RuntimeWarning: Parent module 'apiary_hooks' not found while handling absolute import
      from courses.models import Course, Module
    
    
    pass: GET /api/v1/coursexs/ duration: NaNms
    pass: POST /api/v1/coursexs/ duration: NaNms
    pass: GET /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/ duration: NaNms
    pass: DELETE /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/ duration: NaNms
    skip: PATCH /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/
    pass: PUT /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/ duration: NaNms
    pass: GET /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/modules/ duration: NaNms
    fail: POST /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/modules/ duration: 57ms
    skip: GET /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/modules/1db1a8439cbf4a8f8c395ad63fb43e8a/
    skip: DELETE /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/modules/1db1a8439cbf4a8f8c395ad63fb43e8a/
    skip: PATCH /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/modules/1db1a8439cbf4a8f8c395ad63fb43e8a/
    skip: PUT /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/modules/1db1a8439cbf4a8f8c395ad63fb43e8a/
    skip: GET /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/ccxs
    skip: POST /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/ccxs
    skip: GET /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/ccxs/bcfa43b4
    skip: DELETE /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/ccxs/bcfa43b4
    skip: PATCH /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/ccxs/bcfa43b4
    skip: PUT /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/ccxs/bcfa43b4
    skip: GET /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/modules
    skip: POST /api/v1/ccxs/7e0e52d0386411df81ce001b631bdd31/modules/bcfa43b4
    skip: DELETE /api/v1/ccxs/7e0e52d0386411df81ce001b631bdd31/modules/bcfa43b4
    info: Displaying failed tests...
    fail: POST /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/modules/ duration: 57ms
    fail: body: At '/price_per_seat_cents' Invalid type: null (expected number)
    
    request: 
    body: 
    {
      "title": "Introduction to Quantum Bits",
      "subchapters": [
        "Quarks and Similar things",
        "Things that are not quarks"
      ]
    }
    headers: 
        Content-Length: 140
        Content-Type: application/json
        User-Agent: Dredd/1.0.1 (Linux 3.19.0-23-generic; x64)
    
    uri: /api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/modules/
    method: POST
    
    
    expected: 
    body: 
    {
      "uuid": "1140283aa1b24f5e895e97a76a339040",
      "title": "Introduction to Quantum Bits",
      "price_per_seat_cents": null,
      "subchapters": [],
      "course": "http://localhost:8000/api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/",
      "url": "/api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/modules/1140283aa1b24f5e895e97a76a339040/"
    }
    headers: 
        Content-Type: application/json
        Location: /coursexs/7e0e52d0386411df81ce001b631bdd31/modules/{uuid}/
    
    bodySchema: {"$schema": "http://json-schema.org/draft-04/schema#", "required": ["price_per_seat_cents"], "type": "object", "properties": {"uuid": {"type": "string"}, "title": {"type": "string"}, "url": {"type": "string", "description": "url of the module"}, "price_per_seat_cents": {"type": "number", "description": "price in cents to avoid poor decimal support"}, "course": {"type": "string", "description": "url of the parent course"}, "subchapters": {"type": "array"}}, "nullable": ["price_per_seat_cents"]}
    statusCode: 201
    
    
    actual: 
    body: 
    {
      "uuid": "1143d755c5e547d39a715c17460ddd76",
      "title": "Introduction to Quantum Bits",
      "subchapters": [
        "Quarks and Similar things",
        "Things that are not quarks"
      ],
      "course": "http://localhost:8000/api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/",
      "price_per_seat_cents": null,
      "url": "/api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/modules/1143d755c5e547d39a715c17460ddd76/"
    }
    headers: 
        vary: Accept, Cookie
        server: WSGIServer/0.1 Python/2.7.9
        location: http://localhost:8000/api/v1/coursexs/7e0e52d0386411df81ce001b631bdd31/modules/1143d755c5e547d39a715c17460ddd76/
        allow: GET, POST, HEAD, OPTIONS
        date: Fri, 06 Nov 2015 19:43:01 GMT
        x-frame-options: SAMEORIGIN
        content-type: application/json
    
    statusCode: 201
    
    
    
    complete: 6 passing, 1 failing, 0 errors, 14 skipped, 21 total
    complete: Tests took 5098ms
    Hook handler closed with status: null
    complete: See results in Apiary at: https://app.apiary.io/public/tests/run/89718e6a-bf63-450f-8875-f18c009be39e
    
    
  16. 26 remaining items

  17. fungjj92 commented on Feb 10, 2017

    @fungjj92
  18. philsturgeon commented on Jul 10, 2017

    @philsturgeon

    Swagger is just JSON Schema,

    Oh I really really wish this was true, but it isn't.

    Unlike @fungjj92 suggested, type: [string, 'null'] is not valid Swagger (even though it is valid JSON Schema).

    swagger-api/swagger-editor#1302

    Open API 3.0 supports nullable: true, which ReDoc also backported so is what a lot of folks use in v2.0. It's what im using too.

    Can we get some support for this?

  19. honzajavorek commented on Jul 11, 2017

    @honzajavorek
    Contributor

    @philsturgeon Would you mind to raise the question in https://github.com/apiaryio/fury-adapter-swagger/issues/ ? If it's becoming a de-facto standard even for 2.0, I quite like the idea.

  20. philsturgeon commented on Jul 11, 2017

    @philsturgeon
  21. jshbrntt commented on Jan 16, 2018

    @jshbrntt

    For those who just want there tests to work when a response returns null for a field just change the type in the specification from.

          id:
            type: integer
            description: The ID of something.
            minimum: 0

    To the following.

          id:
            type:
              - integer
              - 'null'
            description: The ID of something.
            minimum: 0

    Your Dredd tests should now accept null for the field.

    EDIT: Don't do this although it passes validation its technically not valid and breaks tools like swagger-codegen

    The x-nullable extension attribute is the way to go, I just need to find I way to make the tests pass in the same way it does when defining type: ['integer', null].

  22. scythargon commented on Mar 9, 2018

    @scythargon

    @synthecypher Hi! Have you found it? Regarding

    The x-nullable extension attribute is the way to go, I just need to find I way to make the tests pass in the same way it does when defining type: ['integer', null].

    I'm struggling with the same issue currently

  23. InfopactMLoos commented on Mar 26, 2018

    @InfopactMLoos

    Since the fury-adapter-swagger issue got solved (apiaryio/fury-adapter-swagger#112) when can we expect this to be available in Dredd?

  24. added a commit that references this issue on Mar 26, 2018
    a049ffa
  25. reopened this on Mar 26, 2018
  26. kylef commented on Mar 26, 2018

    @kylef
    Member

    #993 will make this available to Dredd.

  27. InfopactMLoos commented on May 1, 2018

    @InfopactMLoos

    I must be missing something, I

    • updated to dredd 5.1.6,
    • added the x-nullable attribute with value true

    But I still get an error:

    body: At '/customer_reference' Invalid type: null (expected string)

    This is my swagger definition for the property:

    "customer_reference": {
      "type": "string",
      "description": "(Optional) reference tag for customer",
      "x-nullable": true
    }
    

    I thought this would work but did I forget or misunderstood something?

  28. kylef commented on May 1, 2018

    @kylef
    Member

    @InfopactMLoos Looks like you're hitting a bug because x-nullable is not being applied recursively (only at root of the schema). I've fixed this in apiaryio/fury-adapter-swagger#172, hopefully we can get this reviewed tomorrow and released into production/Dredd.

  29. InfopactMLoos commented on May 2, 2018

    @InfopactMLoos

    Ah ok that explains it, thanks for the quick response and work. I will await the fix, let me know if I can be of any help.

  30. kylef commented on May 3, 2018

    @kylef
    Member

    @InfopactMLoos Dredd 5.1.7 should include a fix for your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions