Skip to content

Conversation

numbata
Copy link
Contributor

@numbata numbata commented Aug 24, 2025

This PR fixes a GrapeSwagger::Errors::SwaggerSpec error that occurred when attempting to generate a Swagger 2.0 schema for an entity with no exposed properties.

The Swagger 2.0 specification does not explicitly forbid empty schemas. This change aligns the gem's behavior with the specification by removing a self-imposed validation that raised an error for empty models

Fixes #962

This commit relaxes a validation check that prevented the creation of an empty
definitions or properties object in the Swagger 2.0 schema.

The previous behavior would raise a GrapeSwagger::Errors::SwaggerSpec exception when
a model, such as an entity with only hidden properties, resulted in an empty
definition. This new behavior is more in line with the Swagger specification, which
does not forbid such schemas.

The fix involves removing the redundant if properties&.any? check and its associated
error, allowing the parser to correctly build an empty but valid model.
@grape-bot
Copy link

1 Warning
⚠️ Unless you're refactoring existing code or improving documentation, please update CHANGELOG.md.

Here's an example of a CHANGELOG.md entry:

* [#963](https://github.com/ruby-grape/grape-swagger/pull/963): Allow empty model definitions for swagger 2.0 - [@numbata](https://github.com/numbata).

Generated by 🚫 Danger

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.

documentation isn't respected when generated definitions include nested entities
2 participants