README.md in oas_rails-0.4.5 vs README.md in oas_rails-0.5.0

- old
+ new

@@ -27,11 +27,11 @@ ## Motivation After experiencing the interactive documentation in Python's fast-api framework, I sought similar functionality in Ruby on Rails. Unable to find a suitable solution, I [asked on Stack Overflow](https://stackoverflow.com/questions/71947018/is-there-a-way-to-generate-an-interactive-documentation-for-rails-apis) years ago. Now, with some free time while freelancing as an API developer, I decided to build my own tool. -**Note**: This is not yet a production-ready solution. The code may be rough and behave unexpectedly, but I am actively working on improving it. If you like the idea, please consider contributing to its development. +**Note: This is not yet a production-ready solution. The code may be rough and behave unexpectedly, but I am actively working on improving it. If you like the idea, please consider contributing to its development.** The goal is to minimize the effort required to create comprehensive documentation. By following REST principles in Rails, we believe this is achievable. You can enhance the documentation using [Yard](https://yardoc.org/) tags. ## Table of Contents @@ -118,11 +118,11 @@ - `config.set_default_responses`: Determines whether to add default errors responses to endpoint. Default is `true`. - `config.possible_default_responses`: Array with possible default errors.(Some will be added depending on the endpoint, example: not_found only works with show/update/delete). Default: [:not_found, :unauthorized, :forbidden]. It should be HTTP status code symbols from the list: `[:not_found, :unauthorized, :forbidden, :internal_server_error, :unprocessable_entity]` -- `config.response_body_of_default`: body for use in default responses. It must be a Hash. Default: { message: String } +- `config.response_body_of_default`: body for use in default responses. It must be a String hash like the used in request body tags. Default: "{ message: String }" ## Usage In addition to the information provided in the initializer file and the data that can be extracted from the routes and methods automatically, it is essential to document your API in the following way. The documentation is created **with the help of YARD**, so the methods are documented with **comment tags**. @@ -156,17 +156,24 @@ </details> <details> <summary style="font-weight: bold; font-size: 1.2em;">@request_body</summary> -**Structure**: `@request_body text [type] structure` +**Structure**: `@request_body text [type<structure>]` Documents the request body needed by the endpoint. The structure is optional if you provide a valid Active Record class. Use `!` to indicate a required request body. **Example**: -`# @request_body The user to be created [Hash] {user: {name: String, age: Integer, password: String}}` +`# @request_body The user to be created [!Hash{user: {name: String, age: Integer, password: String}}]` + +`# @request_body The user to be created [!User]` + +`# @request_body The user to be created [User]` + +`# @request_body The user to be created [!Hash{user: {name: String, age: Integer, password: String, surnames: Array<String>, coords: Hash{lat: String, lng: String}}}]` + </details> <details> <summary style="font-weight: bold; font-size: 1.2em;">@request_body_example</summary> @@ -180,17 +187,20 @@ </details> <details> <summary style="font-weight: bold; font-size: 1.2em;">@response</summary> -**Structure**: `@response text(code) [type] structure` +**Structure**: `@response text(code) [type<structure>]` Documents the responses of the endpoint and overrides the default responses found by the engine. **Example**: -`# @response User not found by the provided Id(404) [Hash] {success: Boolean, message: String}` +`# @response User not found by the provided Id(404) [Hash{success: Boolean, message: String}]` + +`# @response Validation errors(422) [Hash{success: Boolean, erros: Array<Hash{field: String, type: String, detail: Array<String>}>}]` + </details> <details> <summary style="font-weight: bold; font-size: 1.2em;">@tag</summary> @@ -248,21 +258,21 @@ # @auth [bearer] # # This method show a User by ID. The id must exist of other way it will be returning a **`404`**. # # @parameter id(path) [Integer] Used for identify the user. - # @response Requested User(200) [Hash] {user: {name: String, email: String, created_at: DateTime }} - # @response User not found by the provided Id(404) [Hash] {success: Boolean, message: String} - # @response You don't have the right permission for access to this resource(403) [Hash] {success: Boolean, message: String} + # @response Requested User(200) [Hash{user: {name: String, email: String, created_at: DateTime }}] + # @response User not found by the provided Id(404) [Hash{success: Boolean, message: String}] + # @response You don't have the right permission for access to this resource(403) [Hash{success: Boolean, message: String}] def show render json: @user end # @summary Create a User # @no_auth # - # @request_body The user to be created. At least include an `email`. [User!] + # @request_body The user to be created. At least include an `email`. [!User] # @request_body_example basic user [Hash] {user: {name: "Luis", email: "luis@gmail.ocom"}} def create @user = User.new(user_params) if @user.save @@ -274,10 +284,10 @@ # A `user` can be updated with this method # - There is no option # - It must work # @tags users, update - # @request_body User to be created [Hash] {user: { name: String, email: String, age: Integer}} + # @request_body User to be created [!Hash{user: { name: String, email: !String, age: Integer, available_dates: Array<Date>}}] # @request_body_example Update user [Hash] {user: {name: "Luis", email: "luis@gmail.com"}} # @request_body_example Complete User [Hash] {user: {name: "Luis", email: "luis@gmail.com", age: 21}} def update if @user.update(user_params) render json: @user