Skip to content

Not null constraint is not handled correctly #385

@ivan-hristov-abx

Description

@ivan-hristov-abx

Summary

In my json schema I specify the field's type as number. E.g.:

     "longitude": {
          "custom_label": "Coordinates Longitude",
          "description": "The geographical coordinates longitude that represent the center point.",
          "type": "number"
      }

Then my generated code doesn't validate that the provided value for a number is not null. It handles the required check correctly though. The generated code is:

func (j *MyObjectName) UnmarshalJSON(value []byte) error {
      var raw map[string]interface{}
      if err := json.Unmarshal(value, &raw); err != nil {
      	  return err
      }
      if _, ok := raw["latitude"]; raw != nil && !ok {
      	  return fmt.Errorf("field latitude in MyObjectName: required")
      }
      ....

I tried doing stuff like specifying "not": { "type": "null" } but in vain.

Expected

I would expected that there is a check like

latitude ok := raw["latitude"]
if raw != nil && !ok {
    return fmt.Errorf("field latitude in MyObjectName: required")
}
// not null check
if latitude != nil {
    return fmt.Errorf("field latitude in MyObjectName should not be null")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions