Skip to content

Commit 28eb8ce

Browse files
committed
Add AGENTS.md with progressive disclosure documentation
- Minimal root AGENTS.md with essential commands and constraints - docs/testing.md: Test patterns, shared contexts, issue regression specs - docs/contributing.md: PR requirements, CHANGELOG format, danger checks - docs/architecture.md: Component overview and data flow
1 parent 87a807e commit 28eb8ce

4 files changed

Lines changed: 215 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# grape-swagger-entity
2+
3+
Adapter for grape-swagger that parses Grape::Entity classes into OpenAPI schema definitions.
4+
5+
## Quick Reference
6+
7+
```bash
8+
bundle install # Install dependencies
9+
bundle exec rspec # Run tests
10+
bundle exec rubocop # Run linter
11+
bundle exec rubocop -a # Auto-fix linter issues
12+
```
13+
14+
## Key Constraints
15+
16+
- Ruby >= 3.0
17+
- All files must start with `# frozen_string_literal: true`
18+
- CHANGELOG.md entry required for every PR (danger enforces this)
19+
20+
## Documentation
21+
22+
- [Testing Patterns](docs/testing.md)
23+
- [Contributing Guidelines](docs/contributing.md)
24+
- [Architecture Overview](docs/architecture.md)

docs/architecture.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Architecture Overview
2+
3+
## Purpose
4+
5+
This gem registers a model parser with grape-swagger that converts `Grape::Entity` classes into OpenAPI schema definitions.
6+
7+
## Core Components
8+
9+
```
10+
lib/grape-swagger/entity/
11+
├── parser.rb # Main parser - converts Entity to OpenAPI schema
12+
├── attribute_parser.rb # Parses individual exposure attributes
13+
├── helper.rb # Utility methods for model naming, discriminators
14+
└── version.rb # Gem version
15+
```
16+
17+
### Parser (`parser.rb`)
18+
19+
Entry point for entity parsing. Responsibilities:
20+
- Extract exposures from Grape::Entity
21+
- Handle nested entities and `using:` references
22+
- Process `merge: true` exposures
23+
- Handle inheritance with `allOf` and discriminators
24+
- Determine required fields
25+
26+
### AttributeParser (`attribute_parser.rb`)
27+
28+
Converts individual exposure options to OpenAPI property schema:
29+
- Maps Ruby types to OpenAPI types
30+
- Handles arrays (`is_array: true`)
31+
- Processes enums (`values:`)
32+
- Adds constraints (min/max, minLength/maxLength)
33+
34+
### Helper (`helper.rb`)
35+
36+
Utilities for:
37+
- Model name resolution (strips Entity/Entities suffix)
38+
- Discriminator detection for inheritance
39+
- Root exposure extraction
40+
41+
## Data Flow
42+
43+
```
44+
Grape::Entity class
45+
46+
47+
Parser.call
48+
49+
├── extract_params (get exposures)
50+
51+
├── parse_grape_entity_params
52+
│ │
53+
│ ├── AttributeParser (per exposure)
54+
│ │
55+
│ └── parse_nested (for nested blocks)
56+
57+
└── handle_discriminator (inheritance)
58+
59+
60+
[properties_hash, required_array]
61+
```
62+
63+
## Integration Point
64+
65+
Registered with grape-swagger in `lib/grape-swagger-entity.rb`:
66+
67+
```ruby
68+
GrapeSwagger.model_parsers.register(GrapeSwagger::Entity::Parser, Grape::Entity)
69+
```
70+
71+
grape-swagger calls `Parser.new(model, endpoint).call` when it encounters a `Grape::Entity` subclass.

docs/contributing.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Contributing Guidelines
2+
3+
## PR Requirements
4+
5+
Every PR must include:
6+
7+
1. **CHANGELOG.md entry** - Add under `### X.X.X (Next)` in the appropriate section:
8+
```markdown
9+
#### Fixes
10+
* [#123](https://github.com/ruby-grape/grape-swagger-entity/pull/123): Brief description - [@username](https://github.com/username).
11+
```
12+
13+
2. **Passing CI** - RuboCop + RSpec must pass
14+
15+
3. **Tests** - New functionality needs specs; bug fixes need regression tests
16+
17+
## CHANGELOG Format
18+
19+
```markdown
20+
### 0.7.1 (Next)
21+
22+
#### Features
23+
24+
* Your contribution here.
25+
26+
#### Fixes
27+
28+
* [#PR](URL): Description - [@author](URL).
29+
```
30+
31+
- Use `Features` for new functionality
32+
- Use `Fixes` for bug fixes and maintenance
33+
34+
## Commit Messages
35+
36+
Follow conventional style:
37+
- `Fix #123: description` for bug fixes
38+
- `Add feature description` for features
39+
- `Update dependency/docs` for maintenance
40+
41+
## Code Style
42+
43+
RuboCop enforces style. Key rules:
44+
- `frozen_string_literal: true` pragma required
45+
- Consistent hash indentation
46+
- No trailing whitespace
47+
48+
```bash
49+
bundle exec rubocop -a # Auto-fix most issues
50+
```
51+
52+
## Danger Checks
53+
54+
CI runs danger which enforces:
55+
- CHANGELOG entry present
56+
- Table of Contents in README is current
57+
- PR has description

docs/testing.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Testing Patterns
2+
3+
## Running Tests
4+
5+
```bash
6+
bundle exec rspec # Run all tests
7+
bundle exec rspec spec/path/file.rb # Run specific file
8+
bundle exec rspec -e "description" # Run matching examples
9+
```
10+
11+
## Test Structure
12+
13+
```
14+
spec/
15+
├── grape-swagger/
16+
│ ├── entity_spec.rb # Main module specs
17+
│ ├── entity/
18+
│ │ ├── parser_spec.rb # Parser unit tests
19+
│ │ └── attribute_parser_spec.rb
20+
│ └── entities/
21+
│ └── response_model_spec.rb # Integration tests
22+
├── issues/ # Regression tests for GitHub issues
23+
│ └── 962_polymorphic_entity_... # Named by issue number
24+
└── support/
25+
└── shared_contexts/ # Reusable test setup
26+
```
27+
28+
## Shared Contexts
29+
30+
Use shared contexts for common API setups:
31+
32+
```ruby
33+
require 'spec_helper'
34+
require_relative '../../support/shared_contexts/this_api'
35+
36+
describe SomeClass do
37+
include_context 'this api'
38+
# ...
39+
end
40+
```
41+
42+
## Issue Regression Tests
43+
44+
When fixing a bug, create a spec in `spec/issues/` named `{issue_number}_{brief_description}_spec.rb`:
45+
46+
```ruby
47+
# spec/issues/123_some_bug_spec.rb
48+
require 'spec_helper'
49+
50+
describe '#123 brief description of the issue' do
51+
# Test that reproduces and verifies the fix
52+
end
53+
```
54+
55+
## Testing with Different Gem Versions
56+
57+
Environment variables control dependency versions:
58+
59+
```bash
60+
GRAPE_VERSION=2.0.0 bundle update grape
61+
GRAPE_SWAGGER_VERSION=HEAD bundle update grape-swagger
62+
GRAPE_ENTITY_VERSION=1.0.1 bundle update grape-entity
63+
```

0 commit comments

Comments
 (0)