Skip to content

Make entity fields required by default #80

@olivier-thatch

Description

@olivier-thatch

Currently, grape-swagger-entity assumes that required is false unless it's explicitly set with documentation: { required: true }:

params.select { |_, options| options.fetch(:documentation, {}).fetch(:required, false) }

grape-entity always renders fields by default. Conditional exposure is an opt-in feature: https://github.com/ruby-grape/grape-entity?tab=readme-ov-file#conditional-exposure

I think it would make more sense to change the behavior as follows:

  • if options.dig(:documentation, :required) is set, use that
  • otherwise, if options[:if] is set, set required to false
  • otherwise, set required to true

What do you think?

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