Skip to content

Commit

Permalink
📝 Docs for spec and rswag
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroAugustoRamalhoDuarte committed Jan 4, 2023
1 parent 64b4214 commit ddfd4ac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ Following [Switch Dreams's](https://www.switchdreams.com.br/]) coding practices,

- [Automatic rest api crud generation](#example)
- [Nested Resource](#nested-resource)
- [Modular error handler](#modular-error-handler)
- :goal_net: [Modular error handler](#modular-error-handler)
- :memo: [Automated documentation](#specsdocs)
- [Resource ordering](#ordering)
- [Resource filter](#filtering)

## Next Features

- Generate nested resource end-points 🚧
- Automated documentation 🚧 https://github.com/SwitchDreams/rest-api-generator/issues/12
- Serialization https://github.com/SwitchDreams/rest-api-generator/issues/14
https://github.com/SwitchDreams/rest-api-generator/issues/11
- Pagination https://github.com/SwitchDreams/rest-api-generator/issues/15
Expand Down Expand Up @@ -116,6 +115,7 @@ For a better experience you can override some methods from the
| father | Generate nested resource | nil | --father Users |
| scope | Scope the resource for other route or namespace organization | nil | --scope Api::V1 |
| eject | Eject the controller to high customization | false | true |
| spec | Choose the spec format. Current options: "rspec" or "rswag" | rspec | --spec rswag |

#### Scope

Expand Down Expand Up @@ -225,6 +225,24 @@ class CarsController < ApplicationController
end
```

#### Specs/Docs

The default generated spec for this gem is using plain rspec, but you can choose rswag, for scaffold you specs and docs
at the same time:

For this you need to setup https://github.com/rswag/rswag and you the following flag when generating resources.

```shell
rails g rest_api_generator:resource Car name:string color:string --spec rswag
```

This spec options work as generators too, so you can call them individually:

```shell
# rest_api_generator:spec:rswag or rest_api_generator:spec:rspec
rails g rest_api_generator:spec:rswag Car name:string color:string
```

### Resource Features

#### Modular Error Handler
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/generators/rest_api_generator/resource_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,16 @@
it { is_expected.to contain(/module Api::Country/) }
end
end

context "with custom spec" do
before do
run_generator(["user", "--spec", "rswag"])
end

describe "rswag file" do
subject { file("spec/requests/users_spec.rb") }

it { is_expected.to exist }
end
end
end

0 comments on commit ddfd4ac

Please sign in to comment.