Add additional parameter validation support

Issue #9 resolved
James Navin created an issue

Currently parameter validation is limited to simple format, min/max and enum checks.

The OAI spec includes support for regex and other parameter specifications. Should add support for these validation checks.

Comments (8)

  1. Matt Smith

    @jfnavin Could you point me in the right direction to get started on adding this?

    I'm trying to use this library and I need pattern validation and was shocked and dismayed to find it's still unimplemented for definition properties referenced through a $ref

  2. James Navin reporter

    Hi Matt,

    Could you provide an example swagger spec and request that illustrates the problem you're seeing? If you're using pattern properties in JSON schema it should work (I just did a couple quick unit tests and they seem to pass). If it doesn't its a bug and should be raised as such.

    Thanks, James

  3. Matt Smith

    Sure thing. Here's an example that came up when trying to validate UUID parameters –– when I run a request with an invalid UUID against this spec I get no errors. I do get an error if, e.g. I pass in something of an invalid type.

    Please let me know if this is a bug or a known deficiency (or if I'm doing something wrong).

    {
      "swagger": "2.0",
      "info": {
        "version": "1.0",
        "title": "Example"
      },
      "basePath": "/",
      "schemes": [ "http" ],
      "consumes": [ "application/json" ],
      "produces": [ "application/json" ],
      "paths": {
        "/": {
          "post": {
            "parameters": [ {
                "in": "body",
                "name": "body",
                "required": true,
                "schema": {
                  "$ref": "#/definitions/Thing"
                }
              } ],
            "responses": {"201": {"description": "" }}
          }
        }
      },
    
      "definitions": {
        "Thing": {
          "type": "object",
          "required": [ "some_uuid" ],
          "properties": {
            "some_uuid": {
              "$ref": "#/definitions/uuid"
            }
          }
        },
    
        "uuid": {
          "type": "string",
          "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
        }
      }
    }
    
  4. Matt Smith

    Sorry forgot to include a request that should fail but passes:

    curl -v -XPOST HOST/ -d '{"some_uuid": "not a pattern match!!"}'
    
  5. James Navin reporter

    Sorry Matt - I haven't had time to look at this closely yet. From a quick look it definitely seems like a bug - I'll try to get some time this week to look at it in more detail.

    Cheers, James

  6. James Navin reporter

    I have looked into the above example and it does appear to be a bug - I think its something to do with the multiple levels of $ref redirection. Ive raised #44 to track it.

  7. Log in to comment