Skip to content

Feat: Add configurable GrapeOAS.entity_exposure_required_default - #89

Open
abeljim8am wants to merge 1 commit into
numbata:mainfrom
abeljim8am:exposure-required-default
Open

abeljim8am wants to merge 1 commit into
numbata:mainfrom
abeljim8am:exposure-required-default

Conversation

@abeljim8am

Copy link
Copy Markdown
Contributor

Summary

Every expose :foo without an explicit
documentation: { required: ... } is currently marked required. This is
the outlier in the Ruby/OpenAPI ecosystem (grape-swagger and most other
generators default exposures to optional unless required: true is 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 (default true).
ExposureProcessor#determine_required consults the flag when an exposure
has no explicit required: value.

Configuration Exposure Required?
true (default) expose :foo yes
false expose :foo no
Either expose :foo, documentation: { required: true } yes
Either expose :foo, documentation: { required: false } no

Conditional exposures (if:/unless:) and explicit required: values
are unaffected.

@abeljim8am abeljim8am changed the title Add configurable GrapeOAS.entity_exposure_required_default Feat: Add configurable GrapeOAS.entity_exposure_required_default Apr 24, 2026
@github-actions

github-actions Bot commented Apr 26, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

@abeljim8am
abeljim8am force-pushed the exposure-required-default branch from b22fbc8 to 6a9f88c Compare April 30, 2026 21:18
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
abeljim8am force-pushed the exposure-required-default branch from 6a9f88c to 6ce3a6f Compare July 23, 2026 22:22
@bogdan

bogdan commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Maybe can be more general: entity_exposure_default_options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants