passerelle 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +54 -0
- data/Rakefile +12 -0
- data/lib/passerelle/schema.rb +80 -0
- data/lib/passerelle/version.rb +5 -0
- data/lib/passerelle.rb +12 -0
- metadata +77 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d4d615ed2f33f0e8fa815939e2c408f7d239289a59b7d0a306d1adf46181fa9b
|
|
4
|
+
data.tar.gz: 6a2b031da7ab9c6559a3b22e7bc64bfa4d47fd94edaaa45614135c7d28cee2ac
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a92e7567046538bb461f60459ca06752227852303e5a86e8f1214d54a7c5ff4e4e9e8332fa6e33294438721764245de3ec4aac8115d9bd52c201714290a11fde
|
|
7
|
+
data.tar.gz: a2bb38d607fe0312453b9937ad666f5707f9b51ffb786bdbfe2ea1f739992a32364de79705dfcf6667daa8c639a63f1c8fda9df0d5a2923dea9852db2c6f43fa
|
data/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Passerelle
|
|
2
|
+
|
|
3
|
+
**Passerelle** is a convention-over-configuration OpenAPI schema builder for Rails. It's a simple engine you mount in your routes that automatically generates OpenAPI 3.0 schemas from your Rails models.
|
|
4
|
+
|
|
5
|
+
> **⚠️ Work in Progress**: Passerelle is under development. Nothing works yet.
|
|
6
|
+
|
|
7
|
+
## Philosophy
|
|
8
|
+
|
|
9
|
+
- **Convention first**: Your database and ActiveRecord layer dictate the schema defaults. Easy to keep aligned with changes.
|
|
10
|
+
- **Write as little as possible, as much as necessary**: Layer in types and customizations only where needed. Convention handles the rest.
|
|
11
|
+
- **Verifiable**: Generate schema dumps, test against them, commit and track changes.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Add this line to your application's Gemfile:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem 'passerelle'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
And then execute:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
bundle install
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
1. Create a schema class:
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
# app/api/api_schema.rb
|
|
33
|
+
class ApiSchema < Passerelle::Schema
|
|
34
|
+
# That's it! Convention generates CRUD endpoints for all models
|
|
35
|
+
end
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Generate and view your OpenAPI spec:
|
|
39
|
+
|
|
40
|
+
```ruby
|
|
41
|
+
ApiSchema.new.to_json # => Full OpenAPI 3.0 specification
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Development
|
|
45
|
+
|
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
47
|
+
|
|
48
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
49
|
+
|
|
50
|
+
## Contributing
|
|
51
|
+
|
|
52
|
+
Bug reports, feature requests, and ideas are welcome on GitHub at <https://github.com/manufaktor/passerelle>.
|
|
53
|
+
|
|
54
|
+
Note: This project is not currently accepting code contributions (pull requests), but feedback and suggestions are always appreciated.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module Passerelle
|
|
6
|
+
class Schema
|
|
7
|
+
class << self
|
|
8
|
+
# DSL methods will be defined here
|
|
9
|
+
def model(model_class, &block)
|
|
10
|
+
# TODO: Store model configuration
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def endpoint(path, method:, &block)
|
|
14
|
+
# TODO: Store custom endpoint configuration
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def info(&block)
|
|
18
|
+
# TODO: Store API info (title, version, description)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def server(url)
|
|
22
|
+
# TODO: Store server URL
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def security_scheme(name, &block)
|
|
26
|
+
# TODO: Store security scheme
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def models(*model_classes)
|
|
30
|
+
# TODO: Override default model discovery
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def initialize
|
|
35
|
+
# By convention, discover all ApplicationRecord descendants
|
|
36
|
+
@models = discover_models
|
|
37
|
+
@endpoints = []
|
|
38
|
+
@info = default_info
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_json
|
|
42
|
+
to_h.to_json
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def to_h
|
|
46
|
+
{
|
|
47
|
+
openapi: "3.0.3",
|
|
48
|
+
info: @info,
|
|
49
|
+
paths: generate_paths,
|
|
50
|
+
components: generate_components
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def discover_models
|
|
57
|
+
# TODO: Discover all ApplicationRecord descendants
|
|
58
|
+
# ApplicationRecord.descendants
|
|
59
|
+
[]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def default_info
|
|
63
|
+
{
|
|
64
|
+
title: "API",
|
|
65
|
+
version: "1.0.0",
|
|
66
|
+
description: "Auto-generated API by Passerelle"
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def generate_paths
|
|
71
|
+
# TODO: Generate OpenAPI paths from models
|
|
72
|
+
{}
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def generate_components
|
|
76
|
+
# TODO: Generate OpenAPI components (schemas)
|
|
77
|
+
{ schemas: {} }
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
data/lib/passerelle.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: passerelle
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- manufaktor
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '7.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '7.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: zeitwerk
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '2.6'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2.6'
|
|
40
|
+
description: Passerelle (French for 'gateway') automatically generates OpenAPI schemas
|
|
41
|
+
and API endpoints from your Rails models by convention, with configuration where
|
|
42
|
+
you need it.
|
|
43
|
+
email:
|
|
44
|
+
- manufaktor@users.noreply.github.com
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- README.md
|
|
50
|
+
- Rakefile
|
|
51
|
+
- lib/passerelle.rb
|
|
52
|
+
- lib/passerelle/schema.rb
|
|
53
|
+
- lib/passerelle/version.rb
|
|
54
|
+
homepage: https://github.com/manufaktor/passerelle
|
|
55
|
+
licenses: []
|
|
56
|
+
metadata:
|
|
57
|
+
homepage_uri: https://github.com/manufaktor/passerelle
|
|
58
|
+
source_code_uri: https://github.com/manufaktor/passerelle
|
|
59
|
+
changelog_uri: https://github.com/manufaktor/passerelle/blob/main/CHANGELOG.md
|
|
60
|
+
rdoc_options: []
|
|
61
|
+
require_paths:
|
|
62
|
+
- lib
|
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 3.2.0
|
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '0'
|
|
73
|
+
requirements: []
|
|
74
|
+
rubygems_version: 3.6.9
|
|
75
|
+
specification_version: 4
|
|
76
|
+
summary: Convention-over-configuration OpenAPI schema builder for Rails
|
|
77
|
+
test_files: []
|