Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format: uuid cause fail #1218

Closed
utisam opened this issue Jan 26, 2019 · 5 comments
Closed

format: uuid cause fail #1218

utisam opened this issue Jan 26, 2019 · 5 comments

Comments

@utisam
Copy link

utisam commented Jan 26, 2019

Describe the bug

format: uuid of JSON schema cause fail.

fail: body: The id property must be an uuid (current value is "fdb4bbc7-ab05-4269-bdb7-d464f28a959f").

To Reproduce

swagger: "2.0"
info:
  title: UUID format cause fail
  description: Test
  version: 1.0.0
basePath: /
paths:
  /test.json:
    get:
      summary: Test
      responses:
         200:
            description: OK
            schema:
              type: object
              properties:
                id:
                  type: string
                  format: uuid

And response test.json by python3 -m http.server.

{
    "id": "fdb4bbc7-ab05-4269-bdb7-d464f28a959f"
}
npx dredd

Expected behavior

Validate string as an UUID or ignore as an unsupported format.
It makes inconvenient to use with other tools.

What is in your dredd.yml?

init: true
dry-run: null
hookfiles: hooks.js
language: nodejs
require: null
server: python3 -m http.server
server-wait: 3
custom: {}
names: false
only: []
reporter: []
output: []
header: []
sorted: false
user: null
inline-errors: false
details: false
method: []
color: true
level: info
timestamp: false
silent: false
path: []
hooks-worker-timeout: 5000
hooks-worker-connect-timeout: 1500
hooks-worker-connect-retry: 500
hooks-worker-after-connect-wait: 100
hooks-worker-term-timeout: 5000
hooks-worker-term-retry: 500
hooks-worker-handler-host: 127.0.0.1
hooks-worker-handler-port: 61321
config: ./dredd.yml
blueprint: ./example-api.yml
endpoint: 'http://localhost:8000/'

What's your dredd --version output?

dredd v7.1.0 (Linux 4.19.10-300.fc29.x86_64; x64)
@utisam utisam changed the title format: uuid become fail format: uuid cause fail Jan 26, 2019
@utisam
Copy link
Author

utisam commented Jan 26, 2019

As a workaround, I'm writing some hooks.

const hooks = require('hooks');

function patchSchema(v, patch) {
    if (v.type === 'object') {
        const props = Object.values(v.properties);
        for (let i = 0; i < props.length; i += 1) {
        patchSchema(props[i], patch);
        }
    } else if (v.type === 'array') {
        patchSchema(v.items, patch);
    } else {
        patch(v, patch);
    }
}

let stash = null;

hooks.beforeEach((transaction) => {
    stash = {};
});

hooks.beforeEachValidation((transaction) => {
    const { bodySchema } = transaction.expected;
    stash.originalSchema = bodySchema;

    const bodySchemaObject = JSON.parse(bodySchema);
    patchSchema(bodySchemaObject, (v) => {
        if (v.type === 'string' && v.format === 'uuid') {
        // Workaround for uuid format
        const hex = '[0-9a-f]';
        v.pattern = `${hex}{8}-${hex}{4}-4${hex}{3}-[89ab]${hex}{3}-${hex}{12}`;
        delete v.format;
        }
    });
    transaction.expected.bodySchema = JSON.stringify(bodySchemaObject);
});

hooks.afterEach((transaction) => {
    transaction.expected.bodySchema = stash.originalSchema;
});

@honzajavorek
Copy link
Contributor

Thanks! The first step would be to figure out where does the current uuid validation come from. Whether it's the JSON Schema validator we use, the Swagger parser, or something else. I'd say this is a bug.

@chrypnotoad
Copy link

Hello! I am running into this same issue. Has there been any more investigation into this?

@BenSayers
Copy link

I just encountered this issue using Dredd v13.0.1 which includes the PR referenced above, so it doesn't look like this PR has resolved the issue.

@kylef
Copy link
Member

kylef commented Feb 17, 2020

I can confirm via the steps to reproduce by the OP that the original problem here is resolved in Dredd 13.0.1:

$ dredd
pass: GET (200) /test.json duration: 49ms
complete: 1 passing, 0 failing, 0 errors, 0 skipped, 1 total
complete: Tests took 52ms

I had to make minor alterations to the Dredd config to support the newer version of Dredd:

diff --git a/dredd.yml b/dredd.yml
index 46f904ac..973f9744 100644
--- a/dredd.yml
+++ b/dredd.yml
@@ -1,6 +1,5 @@
 init: true
 dry-run: null
-hookfiles: hooks.js
 language: nodejs
 require: null
 server: python3 -m http.server
@@ -17,9 +16,6 @@ inline-errors: false
 details: false
 method: []
 color: true
-level: info
-timestamp: false
-silent: false
 path: []
 hooks-worker-timeout: 5000
 hooks-worker-connect-timeout: 1500

@kylef kylef closed this as completed Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants