Feat: Add configurable GrapeOAS.entity_exposure_required_default - #89
Open
abeljim8am wants to merge 1 commit into
Open
abeljim8am wants to merge 1 commit into
abeljim8am wants to merge 1 commit into
Conversation
Danger ReportNo issues found. |
abeljim8am
force-pushed
the
exposure-required-default
branch
from
April 30, 2026 21:18
b22fbc8 to
6a9f88c
Compare
Introduces a module-level GrapeOAS.entity_exposure_required_default
accessor (mirroring the existing GrapeOAS.logger and
GrapeOAS.schema_ref_name patterns) that controls whether entity
exposures without an explicit documentation[:required] key default to
required in the generated OpenAPI required array.
The default value is true, which keeps output byte-identical for
existing callers — unconditional exposures continue to be marked
required as before. Setting the flag to false opts out of that behavior
so only exposures with an explicit documentation: { required: true } end
up in the required array. Explicit required values (true or false) and
conditional exposures (which stay false) are unaffected.
Implementation: ExposureProcessor#determine_required consults the flag
as its final fallback instead of returning a hard-coded true. The same
method is already used by the nesting-exposure and inheritance paths
(NestingExposure and InheritanceBuilder), so the flag applies uniformly
across entity schema generation.
Coverage: unit tests for the setter (true/false/nil/invalid), unit
tests for determine_required across explicit/conditional/default
branches, and an e2e test proving default output is preserved and that
flipping the flag to false strips default-required properties while
honoring explicit required: true.
Maintainer note: grape-oas's default of 'required by default' is the
outlier in the Ruby/OpenAPI ecosystem — grape-swagger and most other
generators default to optional-unless-explicit. This config addition is
non-breaking, but it also serves as the safe bridge for a potential
future default flip. Open to feedback on whether to pursue that as a
follow-up major-version change.
SAAS-4360
abeljim8am
force-pushed
the
exposure-required-default
branch
from
July 23, 2026 22:22
6a9f88c to
6ce3a6f
Compare
Contributor
|
Maybe can be more general: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every
expose :foowithout an explicitdocumentation: { required: ... }is currently marked required. This isthe outlier in the Ruby/OpenAPI ecosystem (grape-swagger and most other
generators default exposures to optional unless
required: trueis set).This PR adds a config flag so apps can opt out without changing the
existing default. A future major version could flip the default safely
on the back of this flag.
What changed
Added
GrapeOAS.entity_exposure_required_default(defaulttrue).ExposureProcessor#determine_requiredconsults the flag when an exposurehas no explicit
required:value.true(default)expose :foofalseexpose :fooexpose :foo, documentation: { required: true }expose :foo, documentation: { required: false }Conditional exposures (
if:/unless:) and explicitrequired:valuesare unaffected.