jsonschema-generator icon indicating copy to clipboard operation
jsonschema-generator copied to clipboard

Swagger 2's default and allowableValues do not consider the property's type

Open Nephery opened this issue 7 months ago • 3 comments

For the following Swagger 2 module properties:

From @Schema(allowableValues = …) on fields/methods, derive its "const"/"enum". From @Schema(defaultValue = …) on fields/methods, derive its "default".

The outputted JSON always treats them as Strings, and does not consider the actual type of the property.

For example, if I have the following:

public class TestSchema {
	@Schema(allowableValues = "true")
	public boolean myRestrictedBoolean;
}

This would produce a schema like:

{
  "type" : "object",
  "properties" : {
    "myRestrictedBoolean" : {
      "type" : "boolean",
      "const" : "true"
    }
  }
}

Instead of "const" : "true", I would have expected this to be "const" : true (i.e. not a String value). The same happens for any other primitive types.

Nephery avatar Jul 09 '24 17:07 Nephery