-
Notifications
You must be signed in to change notification settings - Fork 41
Improve README and add documentation structure #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
numbata
merged 5 commits into
master
from
58-the-readme-should-more-clearly-explain-the-purpose-of-this-gem
Jan 28, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
87a807e
Improve README with comprehensive documentation
numbata 28eb8ce
Add AGENTS.md with progressive disclosure documentation
numbata 6101b79
Move detailed documentation from README to docs/
numbata 777460e
Fix TOC and add CHANGELOG entry for #91
numbata abdd294
Address review comments
numbata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # grape-swagger-entity | ||
|
|
||
| Adapter for grape-swagger that parses Grape::Entity classes into OpenAPI schema definitions. | ||
|
|
||
| ## Quick Reference | ||
|
|
||
| ```bash | ||
| bundle install # Install dependencies | ||
| bundle exec rspec # Run tests | ||
| bundle exec rubocop # Run linter | ||
| bundle exec rubocop -a # Auto-fix linter issues | ||
| ``` | ||
|
|
||
| ## Key Constraints | ||
|
|
||
| - Ruby >= 3.0 | ||
| - All files must start with `# frozen_string_literal: true` | ||
| - CHANGELOG.md entry required for every PR (danger enforces this) | ||
|
|
||
| ## Documentation | ||
|
|
||
| - [Testing Patterns](docs/testing.md) | ||
| - [Contributing Guidelines](docs/contributing.md) | ||
| - [Architecture Overview](docs/architecture.md) |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Architecture Overview | ||
|
|
||
| ## Purpose | ||
|
|
||
| This gem registers a model parser with grape-swagger that converts `Grape::Entity` classes into OpenAPI schema definitions. | ||
|
|
||
| ## Core Components | ||
|
|
||
| ``` | ||
| lib/grape-swagger/entity/ | ||
| ├── parser.rb # Main parser - converts Entity to OpenAPI schema | ||
| ├── attribute_parser.rb # Parses individual exposure attributes | ||
| ├── helper.rb # Utility methods for model naming, discriminators | ||
| └── version.rb # Gem version | ||
| ``` | ||
|
|
||
| ### Parser (`parser.rb`) | ||
|
|
||
| Entry point for entity parsing. Responsibilities: | ||
| - Extract exposures from Grape::Entity | ||
| - Handle nested entities and `using:` references | ||
| - Process `merge: true` exposures | ||
| - Handle inheritance with `allOf` and discriminators | ||
| - Determine required fields | ||
|
|
||
| ### AttributeParser (`attribute_parser.rb`) | ||
|
|
||
| Converts individual exposure options to OpenAPI property schema: | ||
| - Maps Ruby types to OpenAPI types | ||
| - Handles arrays (`is_array: true`) | ||
| - Processes enums (`values:`) | ||
| - Adds constraints (min/max, minLength/maxLength) | ||
|
|
||
| ### Helper (`helper.rb`) | ||
|
|
||
| Utilities for: | ||
| - Model name resolution (strips Entity/Entities suffix) | ||
| - Discriminator detection for inheritance | ||
| - Root exposure extraction | ||
|
|
||
| ## Data Flow | ||
|
|
||
| ``` | ||
| Grape::Entity class | ||
| │ | ||
| ▼ | ||
| Parser.call | ||
| │ | ||
| ├── extract_params (get exposures) | ||
| │ | ||
| ├── parse_grape_entity_params | ||
| │ │ | ||
| │ ├── AttributeParser (per exposure) | ||
| │ │ | ||
| │ └── parse_nested (for nested blocks) | ||
| │ | ||
| └── handle_discriminator (inheritance) | ||
| │ | ||
| ▼ | ||
| [properties_hash, required_array] | ||
| ``` | ||
|
|
||
| ## Integration Point | ||
|
|
||
| Registered with grape-swagger in `lib/grape-swagger/entity.rb`: | ||
|
|
||
| ```ruby | ||
| GrapeSwagger.model_parsers.register(GrapeSwagger::Entity::Parser, Grape::Entity) | ||
| ``` | ||
|
|
||
| grape-swagger calls `Parser.new(model, endpoint).call` when it encounters a `Grape::Entity` subclass. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Contributing Guidelines | ||
|
|
||
| ## PR Requirements | ||
|
|
||
| Every PR must include: | ||
|
|
||
| 1. **CHANGELOG.md entry** - Add under `### X.X.X (Next)` in the appropriate section: | ||
| ```markdown | ||
| #### Fixes | ||
| * [#123](https://github.com/ruby-grape/grape-swagger-entity/pull/123): Brief description - [@username](https://github.com/username). | ||
| ``` | ||
|
|
||
| 2. **Passing CI** - RuboCop + RSpec must pass | ||
|
|
||
| 3. **Tests** - New functionality needs specs; bug fixes need regression tests | ||
|
|
||
| ## CHANGELOG Format | ||
|
|
||
| ```markdown | ||
| ### 0.7.1 (Next) | ||
|
|
||
| #### Features | ||
|
|
||
| * Your contribution here. | ||
|
|
||
| #### Fixes | ||
|
|
||
| * [#PR](URL): Description - [@author](URL). | ||
| ``` | ||
|
|
||
| - Use `Features` for new functionality | ||
| - Use `Fixes` for bug fixes and maintenance | ||
|
|
||
| ## Commit Messages | ||
|
|
||
| Follow conventional style: | ||
| - `Fix #123: description` for bug fixes | ||
| - `Add feature description` for features | ||
| - `Update dependency/docs` for maintenance | ||
|
|
||
| ## Code Style | ||
|
|
||
| RuboCop enforces style. Key rules: | ||
| - `frozen_string_literal: true` pragma required | ||
| - Consistent hash indentation | ||
| - No trailing whitespace | ||
|
|
||
| ```bash | ||
| bundle exec rubocop -a # Auto-fix most issues | ||
| ``` | ||
|
|
||
| ## Danger Checks | ||
|
|
||
| CI runs danger which enforces: | ||
| - CHANGELOG entry present | ||
| - Table of Contents in README is current | ||
| - PR has description |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # Documentation Options | ||
|
|
||
| The `documentation` hash in entity exposures supports the following options: | ||
|
|
||
| ## Type Options | ||
|
|
||
| | Option | Description | Example | | ||
| |--------|-------------|---------| | ||
| | `type` | OpenAPI data type | `String`, `Integer`, `Boolean`, `Float`, `Date`, `DateTime` | | ||
| | `is_array` | Marks field as array type | `true` / `false` | | ||
|
|
||
| ## Description Options | ||
|
|
||
| | Option | Description | Example | | ||
| |--------|-------------|---------| | ||
| | `desc` | Property description | `'User email address'` | | ||
| | `example` | Example value for documentation | `'user@example.com'` | | ||
| | `default` | Default value | `'pending'` | | ||
|
|
||
| ## Validation Options | ||
|
|
||
| | Option | Description | Example | | ||
| |--------|-------------|---------| | ||
| | `required` | Whether field is required | `true` / `false` | | ||
| | `values` | Enum values (array or proc) | `%w[pending active]` or `-> { Status.all }` | | ||
| | `minimum` | Minimum value for numeric types | `0` | | ||
| | `maximum` | Maximum value for numeric types | `100` | | ||
| | `min_length` | Minimum length for strings | `1` | | ||
| | `max_length` | Maximum length for strings | `255` | | ||
| | `min_items` | Minimum items for arrays | `1` | | ||
| | `max_items` | Maximum items for arrays | `10` | | ||
| | `unique_items` | Array items must be unique | `true` | | ||
|
|
||
| ## Display Options | ||
|
|
||
| | Option | Description | Example | | ||
| |--------|-------------|---------| | ||
| | `read_only` | Marks field as read-only | `true` | | ||
| | `hidden` | Hide field from documentation | `true` | | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Basic types | ||
|
|
||
| ```ruby | ||
| expose :id, documentation: { type: Integer, desc: 'Unique identifier' } | ||
| expose :name, documentation: { type: String, desc: 'Full name', required: true } | ||
| expose :active, documentation: { type: Boolean, default: true } | ||
| ``` | ||
|
|
||
| ### Enums | ||
|
|
||
| ```ruby | ||
| expose :status, documentation: { | ||
| type: String, | ||
| desc: 'Current status', | ||
| values: %w[pending active suspended] | ||
| } | ||
| ``` | ||
|
|
||
| ### Numeric constraints | ||
|
|
||
| ```ruby | ||
| expose :age, documentation: { | ||
| type: Integer, | ||
| minimum: 0, | ||
| maximum: 150 | ||
| } | ||
| ``` | ||
|
|
||
| ### String constraints | ||
|
|
||
| ```ruby | ||
| expose :username, documentation: { | ||
| type: String, | ||
| min_length: 3, | ||
| max_length: 20 | ||
| } | ||
| ``` | ||
|
|
||
| ### Arrays | ||
|
|
||
| ```ruby | ||
| expose :tags, documentation: { | ||
| type: String, | ||
| is_array: true, | ||
| desc: 'Associated tags' | ||
| } | ||
| ``` |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.