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

Add flag for validation disabling #182

Closed
cansik opened this issue Mar 11, 2016 · 13 comments
Closed

Add flag for validation disabling #182

cansik opened this issue Mar 11, 2016 · 13 comments
Assignees

Comments

@cansik
Copy link
Contributor

cansik commented Mar 11, 2016

In my swagger definition I have a lot of parameters which contain a valid datatype which then is needed for our automated query builder:

  PropertyGroup:
    properties:
      time_start:
        description: Start time of flare
        type: string
        format: date-time

      nar:
        description: NOAA active region number
        type: number
        format: int32

      lat_hg:
        description: Stonyhurst heliographic latitude of event
        type: number
        format: int32

Now the problem we encounter is, that sometimes the validation of these types is not possible because we need for example nullable types as well.

So my question is, if it is possible to add an option which disables the validation or a method to provide an own validator class for some datatypes?

@hjacobs
Copy link
Contributor

hjacobs commented Mar 15, 2016

@rafaelcaricio @jmcs could you check this?

@rafaelcaricio
Copy link
Collaborator

I was reading about this issue which cover this topic about Swagger/OpenAPI Spec. I would be nice to support x-nullable in Connexion. But I also agree we should have a way to make possible more personalisation of custom types/formats. I will invest some work on that next week.

@rafaelcaricio
Copy link
Collaborator

@cansik Please check if #197 solves partially your problem.

Allowing customisation for validation is the next step.

@cansik
Copy link
Contributor Author

cansik commented Mar 31, 2016

@rafaelcaricio Yes this looks very promising! I'll give it a try this week. Thank you!

@rafaelcaricio
Copy link
Collaborator

@cansik It might interest you. I just added an example how to create custom formats to be used with Connexion #216

@cansik
Copy link
Contributor Author

cansik commented May 19, 2016

@rafaelcaricio Great!

@cansik
Copy link
Contributor Author

cansik commented May 26, 2016

@rafaelcaricio So it is possible to write a validator for format, is it also possible to write one for type?

@rafaelcaricio
Copy link
Collaborator

@cansik You validate types using formats, no? Do you wanna define new types?
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types

@cansik
Copy link
Contributor Author

cansik commented May 26, 2016

@rafaelcaricio Yes your right, but as described in my initial issue, we need to support nullable types. This isn't possible with format validators because e.g. as type we use number. Even if I now create my own format validator nullableint32, the type validator won't let None pass.

So the only possible option I have would be to send the data as string and validate it then with a formatter. Am I right?

@rafaelcaricio
Copy link
Collaborator

@cansik you can define many types for a single field. So in your case you can do:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
      "value": {
        "type": ["integer", "null"],
        "format": "int32"
      }
    }
}

No need for new types. This is pure JSON schema stuff.

@cansik
Copy link
Contributor Author

cansik commented May 26, 2016

@rafaelcaricio Very nice! This works great! Thank you so much!

@cansik cansik closed this as completed May 26, 2016
@jmcs jmcs removed the in progress label May 26, 2016
@jasco
Copy link

jasco commented Jan 21, 2017

@rafaelcaricio great suggestion about using an array of type values. It works great if I manually adjust the swagger.json in the codegen output. Unfortunately, since type does not accept an array in swagger, swagger-codegen rejects the construct.

I was initially hopeful that x-nullable would serve the purpose, but my research so far seems to show that currently x-nullable works at the parameter level but not within an object.

@advance512
Copy link

I agree that this is something that should be supported. I am forced to input 0 as a symbol for null in some properties of body type parameters.

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

6 participants