Skip to content

Optional parameter with default value should NOT be treated as pointers #479

@ilya-direct

Description

@ilya-direct

Schema

schema:
  type: object
  properties:
      name:
          type: string
      comment:
          type: string
          default: ""
  required:
      - name

Generated as:

type AddItemJSONBody struct {
        Name    string `json:"name"`
	Comment    *string `json:"comment,omitempty"`
}

But it would be useful to be (without a pointer):

type AddItemJSONBody struct {
        Name    string `json:"name"`
	Comment    string `json:"comment,omitempty"`
}

within json.unmarshal empty comment should be assigned to default value.

PS pointer values must be checked for nil and that is an additional pain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions