【发布时间】:2020-12-18 07:47:43
【问题描述】:
我正在制作关于 swagger 和使用 YAML 的 API 文档。 这是我的 YAML 代码
swagger: "2.0"
info:
title: Sign_up Api
description: This Will alow user to Signup.
version: 1.0.0
host: e9ea53234b75.ngrok.io
basePath: /customer_app/api/v1
schemes:
- https
paths:
/sign_up:
post:
summary: Return User Credentials After signup.
parameters:
- in: body
name: body
required: true
# type: string
schema:
type: object
properties:
email:
type: string
example: test123@gmail.com
password:
# type: string
example: test123
password_confirmation:
# type: integer
example: test123
name:
type: string
example: testabc
description: User can be signup by providing the listed params & it will return a authentication token and other user params.
produces:
- application/json
responses:
200:
description: User credentials.
properties:
id:
type: string
example: 70020ed1-50fe-4c7e-afed
password:
# type: string
example: pasw123
password_confirmation:
# type: string
example: pasw123
name:
type: string
example: testabc
422:
description: The specified email is invalid (e.g. not following the syntax) or paswwords are not same or missing params.
default:
description: Unexpected error
我在rails中获取我的参数
params.require(:user).permit(:email, :password , :password_confirmation, :uuid, :name)
通过这种方式我从邮递员那里发送我的参数
并得到此响应
<ActionController::Parameters {"user"=><ActionController::Parameters {"email"=>"moon123@gmail.com", "password"=>"moon123", "password_confirmation"=>"moon123", "name"=>"moon123"} permitted: false>, "format"=>:json, "controller"=>"customer_app/api/v1/registrations", "action"=>"create"} permitted: false>
但是通过在 YAML 中使用 user[email] 得到了错误的方式
<ActionController::Parameters {"user[email]"=>"test123@gmail.com", "user[password]"=>"test123", "user[password_confirmation]"=>"test123", "user[name]"=>"testabc", "format"=>:json, "controller"=>"customer_app/api/v1/registrations", "action"=>"create", "registration"=>{"user[email]"=>"test123@gmail.com", "user[password]"=>"test123", "user[password_confirmation]"=>"test123", "user[name]"=>"testabc"}} permitted: false>
我不知道如何编辑我的 YAML 以获得 Postman 的响应。
【问题讨论】:
标签: ruby-on-rails ruby swagger openapi swagger-2.0