openapi_kit 0.1.0.pre.2 → 0.1.0.pre.3
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 +4 -4
- data/README.md +15 -12
- data/lib/openapi_kit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 613a75911e2ca7e79f0eaf2efaf73e8fb5010b80ee1198e80fb7e2d364015d11
|
|
4
|
+
data.tar.gz: 2ecbfb34c60742a6b98e3c1cd29cf235f8a8bacd0ae8d647d952dc4ddce60ac8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b50ef496efb12a30f02420d7c7f0624b34fb4bcae6ccb84883fb34fa69cb0cb7c033c23da45189458b432dcefa30f946172497dfa24e257f4f52ce33132b1efa
|
|
7
|
+
data.tar.gz: ce716d3ace4b5710b3ff8eb8be23b7dc42387208649b2fd398ef1bda64c328405e6acc32cbf5450761f539ba4df779915694d15402447ac6cd6c5eda19112063
|
data/README.md
CHANGED
|
@@ -28,7 +28,7 @@ end
|
|
|
28
28
|
```yaml
|
|
29
29
|
# openapi_kit.yml
|
|
30
30
|
spec: openapi/petstore.yaml
|
|
31
|
-
output: app/api
|
|
31
|
+
output: app/api/petstore/v1
|
|
32
32
|
modules: [Petstore, V1]
|
|
33
33
|
controller_base: Api::BaseController
|
|
34
34
|
principal: "::Petstore::Principal"
|
|
@@ -37,8 +37,8 @@ principal: "::Petstore::Principal"
|
|
|
37
37
|
| Option | Meaning |
|
|
38
38
|
| --- | --- |
|
|
39
39
|
| `spec` | root OpenAPI document, resolved relative to this file |
|
|
40
|
-
| `output` | directory the tree is written
|
|
41
|
-
| `modules` | namespace
|
|
40
|
+
| `output` | directory the tree is written into, which openapi_kit owns |
|
|
41
|
+
| `modules` | namespace every generated constant is declared in, so `Petstore::V1::Types::Pet` |
|
|
42
42
|
| `controller_base` | class the generated controllers inherit from |
|
|
43
43
|
| `principal` | the class a successful authentication produces |
|
|
44
44
|
| `type_mappings` | your Ruby type for a `type:format` pair |
|
|
@@ -57,13 +57,16 @@ app/api/petstore/v1/registry.rb
|
|
|
57
57
|
app/api/petstore/v1/routes.rb
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
Nothing is written outside `output`, and `modules` decides only what the files declare. One
|
|
61
|
+
constant per file at the path that constant implies, counting from `output`, so laying the
|
|
62
|
+
directory out to match the namespace is what lets Rails autoload it. Each run wipes
|
|
63
|
+
`output`, but only after checking openapi_kit generated every `.rb` in it.
|
|
62
64
|
|
|
63
65
|
## Integrating with Rails
|
|
64
66
|
|
|
65
|
-
**Autoload the
|
|
66
|
-
|
|
67
|
+
**Autoload the tree**, if it is not already under `app/`. The root is the directory
|
|
68
|
+
`modules` counts from, not `output` itself. An acronym in `modules` is a directory like any
|
|
69
|
+
other, so it needs an inflection.
|
|
67
70
|
|
|
68
71
|
```ruby
|
|
69
72
|
# config/application.rb
|
|
@@ -125,15 +128,15 @@ module Api
|
|
|
125
128
|
end
|
|
126
129
|
```
|
|
127
130
|
|
|
128
|
-
**Assign the registry.** openapi_kit generates a `Registry` struct with one slot per handler
|
|
129
|
-
authenticator, and controllers read
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
**Assign the registry.** openapi_kit generates a `Registry` struct with one slot per handler
|
|
132
|
+
and authenticator, and controllers read the one you assigned. Rails instantiates controllers
|
|
133
|
+
itself, so they cannot be handed one. Omit a slot, or pass something that does not
|
|
134
|
+
implement its interface, and it does not compile.
|
|
132
135
|
|
|
133
136
|
```ruby
|
|
134
137
|
# config/initializers/openapi_kit.rb
|
|
135
138
|
Rails.application.config.to_prepare do
|
|
136
|
-
Petstore::V1.
|
|
139
|
+
Petstore::V1::Registry.instance = Petstore::V1::Registry.new(
|
|
137
140
|
pets: PetsHandler.new(repo: PetRepo.new),
|
|
138
141
|
system: SystemHandler.new,
|
|
139
142
|
bearer_auth: BearerAuthenticator.new(decoder: TokenDecoder.new)
|
data/lib/openapi_kit/version.rb
CHANGED