Skip to content

Commit

Permalink
Merge pull request #37 from tan12082001/api-documentation
Browse files Browse the repository at this point in the history
Create Api documentation
  • Loading branch information
Wineshuga authored Dec 14, 2023
2 parents 2e2c572 + 15547c8 commit 2b5a6a0
Show file tree
Hide file tree
Showing 16 changed files with 542 additions and 103 deletions.
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ end
gem 'database_cleaner'
gem 'devise-jwt'
gem 'factory_bot_rails'
gem 'jsonapi-serializer', '~> 2.2'
gem 'paranoia', '~> 2.5'
gem 'rack-cors'
gem 'rswag'
gem 'rswag-api'
gem 'rswag-ui'
gem 'shoulda-matchers'

gem 'jsonapi-serializer', '~> 2.2'
gem 'swagger-docs'
gem 'swagger-ui_rails'
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ GEM
shoulda-matchers (5.3.0)
activesupport (>= 5.2.0)
stringio (3.1.0)
swagger-docs (0.2.9)
activesupport (>= 3)
rails (>= 3)
swagger-ui_rails (0.1.7)
thor (1.3.0)
timeout (0.4.1)
tzinfo (2.0.6)
Expand Down Expand Up @@ -301,7 +305,11 @@ DEPENDENCIES
rails-controller-testing
rspec-rails
rswag
rswag-api
rswag-ui
shoulda-matchers
swagger-docs
swagger-ui_rails
tzinfo-data

RUBY VERSION
Expand Down
85 changes: 53 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

# 📗 Table of Contents

- [📖 About the Project](#about-project)
- [🛠 Built With](#built-with)
- [Tech Stack](#tech-stack)
- [Key Features](#key-features)
- [💻 Getting Started](#getting-started)
- [Setup](#setup)
- [Prerequisites](#prerequisites)
- [Install](#install)
- [Usage](#usage)
- [Run tests](#run-tests)
- [Frontend Repository](#frontend-repository)
- [ERD Image](#erd-image)
- [API Documentation](#api-documentation)
- [👥 Authors](#authors)
- [🔭 Future Features](#future-features)
- [🤝 Contributing](#contributing)
- [⭐️ Show your support](#support)
- [🙏 Acknowledgements](#acknowledgements)
- [❓ FAQ (OPTIONAL)](#faq)
- [📝 License](#license)
- [📗 Table of Contents](#-table-of-contents)
- [📖 vehicle booking app ](#-vehicle-booking-app-)
- [🛠 Built With ](#-built-with-)
- [Tech Stack ](#tech-stack-)
- [Key Features ](#key-features-)
- [💻 Getting Started ](#-getting-started-)
- [Prerequisites](#prerequisites)
- [Setup](#setup)
- [Install](#install)
- [Frontend Repository](#frontend-repository)
- [ERD Image](#erd-image)
- [API Documentation](#api-documentation)
- [Usage](#usage)
- [Run tests](#run-tests)
- [👥 Authors ](#-authors-)
- [🔭 Future Features ](#-future-features-)
- [🤝 Contributing ](#-contributing-)
- [⭐️ Show your support ](#️-show-your-support-)
- [🙏 Acknowledgments ](#-acknowledgments-)
- [📝 License ](#-license-)

# 📖 vehicle booking app <a name="about-project"></a>

Expand Down Expand Up @@ -75,35 +75,55 @@ In order to run this project you need:

Use the following URL to clone this project:

https://github.com/tan12082001/Vehicle-Booking-App-Backend.git
```
git clone https://github.com/tan12082001/Vehicle-Booking-App-Backend.git
```

### Install
Open the terminal in the root directory of the project and run the following command to install all dependencies.

bundle install
- bundle install
- secret_base_key generation
In terminal:
* rm credentials.yml.enc
* $ EDITOR="mate --wait" bin/rails credentials:edit

- configure database
In terminal:
* run `rails db:create`
* run `db:migrate`

- Rspec
In terminal:
* bundle exec rails db:schema:load RAILS_ENV=test

### Frontend Repository
Reference the [Frontend Repository](https://github.com/tan12082001/Vehicle-Booking-App-Frontend.git) for the corresponding frontend.

### ERD Image
Add an ERD image to visualize the database schema.
## follow the below link to access
(https://drawsql.app/teams/wineshuga/diagrams/book-appointment)
[ERD image to visualize the database schema](https://drawsql.app/teams/wineshuga/diagrams/book-appointment)

### API Documentation
Reference the API documentation for details on how to interact with the API.
For details on how to interact with the API, view the API documentation. Follow the steps below:

- run server `rails s`
- open in browser `http://localhost:4000/api-docs`

### Usage
To start the development server, run the following command then navigate to `localhost:3000` in your browser.
To start the development server, run the following command then navigate to `localhost:4000` in your browser.

rails s

Open [http://localhost:3000](http://localhost:3000/api/random_greeting) to view it in your browser.
Open [http://localhost:4000](http://localhost:4000) to view it in your browser.


### Run tests
There are no tests to run.
To run tests, use the following command:

```
rspec
```
<p align="right">(<a href="#readme-top">back to top</a>)</p>


Expand All @@ -121,11 +141,12 @@ There are no tests to run.
- GitHub: [@tan12082001](https://github.com/tan12082001)


👤 **Winnie uzochukwu**
👤 **Nweneary Uzochukwu Winnie**

- GitHub: [@winnie](https://github.com/Wineshuga)
- GitHub: [@wineshuga](https://github.com/Wineshuga)
- LinkedIn: [LinkedIn](https://linkedin.com/in/wineshuga)

👤 **Winnie uzochukwu**
👤 **Bolaji Toyib**

- GitHub: [@toyybi bolaji](https://github.com/Simpleshaikh1)

Expand Down
14 changes: 14 additions & 0 deletions config/initializers/rswag_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Rswag::Api.configure do |c|

# Specify a root folder where Swagger JSON files are located
# This is used by the Swagger middleware to serve requests for API descriptions
# NOTE: If you're using rswag-specs to generate Swagger, you'll need to ensure
# that it's configured to generate files in the same folder
c.openapi_root = Rails.root.to_s + '/swagger'

# Inject a lambda function to alter the returned Swagger prior to serialization
# The function will have access to the rack env for the current request
# For example, you could leverage this to dynamically assign the "host" property
#
#c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] }
end
16 changes: 16 additions & 0 deletions config/initializers/rswag_ui.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Rswag::Ui.configure do |c|

# List the Swagger endpoints that you want to be documented through the
# swagger-ui. The first parameter is the path (absolute or relative to the UI
# host) to the corresponding endpoint and the second is a title that will be
# displayed in the document selector.
# NOTE: If you're using rspec-api to expose Swagger files
# (under openapi_root) as JSON or YAML endpoints, then the list below should
# correspond to the relative paths for those endpoints.

c.swagger_endpoint '/api-docs/v1/swagger.yaml', 'API V1 Docs'

# Add Basic Auth in case your API is private
# c.basic_auth_enabled = true
# c.basic_auth_credentials 'username', 'password'
end
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Rails.application.routes.draw do
mount Rswag::Ui::Engine => '/api-docs'
mount Rswag::Api::Engine => '/api-docs'

namespace :api do
devise_for :users,
controllers: {
Expand All @@ -7,7 +10,9 @@
}

resources :cars do
delete 'destroy', on: :member, to: 'cars#destroy'
member do
delete 'destroy'
end
end

get 'all_cars', to: 'cars#index'
Expand Down
40 changes: 20 additions & 20 deletions spec/examples.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
example_id | status | run_time |
---------------------------------------------------- | ------ | --------------- |
./spec/models/car_spec.rb[1:1:1] | passed | 0.00587 seconds |
./spec/models/car_spec.rb[1:1:2] | passed | 0.14159 seconds |
./spec/models/my_reservation_spec.rb[1:1:1] | passed | 0.00397 seconds |
./spec/models/my_reservation_spec.rb[1:1:2] | passed | 0.0029 seconds |
./spec/models/user_spec.rb[1:1:1] | passed | 0.00157 seconds |
./spec/models/user_spec.rb[1:1:2] | passed | 0.002 seconds |
./spec/requests/api/cars_spec.rb[1:1:1] | passed | 0.05168 seconds |
./spec/requests/api/cars_spec.rb[1:2:1:1] | passed | 2.02 seconds |
./spec/requests/api/cars_spec.rb[1:2:2:1] | passed | 1.78 seconds |
./spec/requests/api/cars_spec.rb[1:3:1:1] | passed | 0.02911 seconds |
./spec/requests/api/cars_spec.rb[1:3:2:1] | passed | 0.02891 seconds |
./spec/requests/api/cars_spec.rb[1:4:1:1] | passed | 0.02337 seconds |
./spec/requests/api/cars_spec.rb[1:4:2:1] | passed | 0.55206 seconds |
./spec/requests/api/my_reservations_spec.rb[1:1:1] | passed | 0.02825 seconds |
./spec/requests/api/my_reservations_spec.rb[1:2:1:1] | passed | 0.0311 seconds |
./spec/requests/api/my_reservations_spec.rb[1:2:2:1] | passed | 0.05047 seconds |
./spec/requests/api/registrations_spec.rb[1:1:1:1] | passed | 0.01067 seconds |
./spec/requests/api/registrations_spec.rb[1:1:2:1] | passed | 0.10001 seconds |
./spec/requests/api/sessions_spec.rb[1:1:1:1] | passed | 0.02346 seconds |
./spec/requests/api/sessions_spec.rb[1:1:2:1] | passed | 0.01105 seconds |
./spec/models/car_spec.rb[1:1:1] | passed | 0.00344 seconds |
./spec/models/car_spec.rb[1:1:2] | passed | 0.0022 seconds |
./spec/models/my_reservation_spec.rb[1:1:1] | passed | 0.00311 seconds |
./spec/models/my_reservation_spec.rb[1:1:2] | passed | 0.00317 seconds |
./spec/models/user_spec.rb[1:1:1] | passed | 0.00516 seconds |
./spec/models/user_spec.rb[1:1:2] | passed | 0.00459 seconds |
./spec/requests/api/cars_spec.rb[1:1:1] | passed | 0.02357 seconds |
./spec/requests/api/cars_spec.rb[1:2:1:1] | passed | 0.0264 seconds |
./spec/requests/api/cars_spec.rb[1:2:2:1] | passed | 0.54128 seconds |
./spec/requests/api/cars_spec.rb[1:3:1:1] | passed | 0.08633 seconds |
./spec/requests/api/cars_spec.rb[1:3:2:1] | passed | 0.05279 seconds |
./spec/requests/api/cars_spec.rb[1:4:1:1] | passed | 0.02828 seconds |
./spec/requests/api/cars_spec.rb[1:4:2:1] | passed | 0.58217 seconds |
./spec/requests/api/my_reservations_spec.rb[1:1:1] | passed | 0.02292 seconds |
./spec/requests/api/my_reservations_spec.rb[1:2:1:1] | passed | 0.07591 seconds |
./spec/requests/api/my_reservations_spec.rb[1:2:2:1] | passed | 0.03623 seconds |
./spec/requests/api/registrations_spec.rb[1:1:1:1] | passed | 0.01678 seconds |
./spec/requests/api/registrations_spec.rb[1:1:2:1] | passed | 0.01791 seconds |
./spec/requests/api/sessions_spec.rb[1:1:1:1] | passed | 0.23151 seconds |
./spec/requests/api/sessions_spec.rb[1:1:2:1] | passed | 0.01566 seconds |
4 changes: 2 additions & 2 deletions spec/swagger_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# When you run the 'rswag:specs:swaggerize' rake task, the complete Swagger will
# be generated at the provided relative path under openapi_root
# By default, the operations defined in spec files are added to the first
# document below. You can override this behavior by adding a openapi_spec tag to the
# document below. You can override this behavior by adding a openapi_spec tag to theA
# the root example_group in your specs, e.g. describe '...', openapi_spec: 'v2/swagger.json'
config.openapi_specs = {
'v1/swagger.yaml' => {
Expand All @@ -25,7 +25,7 @@
url: 'https://{defaultHost}',
variables: {
defaultHost: {
default: 'www.example.com'
default: 'localhost:4000'
}
}
}
Expand Down
Loading

0 comments on commit 2b5a6a0

Please sign in to comment.