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?
@rafaelcaricio @jmcs could you check this?
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.
@cansik Please check if #197 solves partially your problem.
Allowing customisation for validation is the next step.
@rafaelcaricio Yes this looks very promising! I'll give it a try this week. Thank you!
@cansik It might interest you. I just added an example how to create custom formats to be used with Connexion https://github.com/zalando/connexion/pull/216
@rafaelcaricio Great!
@rafaelcaricio So it is possible to write a validator for format, is it also possible to write one for type?
@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
@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?
@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.
@rafaelcaricio Very nice! This works great! Thank you so much!
@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.
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.
Most helpful comment
@cansik you can define many types for a single field. So in your case you can do:
No need for new types. This is pure JSON schema stuff.