【ruby on rails】rswag使用

news/2025/1/26 17:46:07/

命令

  • 生成文档
rake rswag

一些代码

# frozen_string_literal: truerequire 'rails_helper'RSpec.configure do |config|config.swagger_root = Rails.root.join('swagger').to_s# the root example_group in your specs, e.g. describe '...', swagger_doc: 'v2/swagger.json'config.swagger_docs = {#  'v1/swagger.yaml' => {'v1/swagger.json' => {   openapi: '3.0.1',info: {title: 'API V1',version: 'v1'},paths: {},servers: [{url: 'http://{defaultHost}',description: '本地开发',variables: {defaultHost: {default: '127.0.0.1:3000'}}},{url: 'https://{defaultHost}',description: '测试服',variables: {defaultHost: {default: 'api.xxx.com' # 默认https}}}],components: {securitySchemes: {# Bearer: {#   description: 'token necessary to use API calls',#   type: :apiKey,#   name: 'X-Admin-Authorization',#   in: :header# }bearer_auth: {type: :http,scheme: :bearer,bearerFormat: 'JWT'}},schemas: {marks: {type: :array,items: {type: :object,properties: {date: { type: :string },score: { type: :number },worksheet: { type: :string }}}},importances: {type: :array,items: {type: :object,properties: {school_id: { type: :integer },importance: { type: :integer }}}},improvement_priorities: {type: :array,items: {type: :object,properties: {priority: { type: :integer },school_id: { type: :integer }}}},subtopics: {type: :array,items: {type: :object,properties: {id: { type: :integer },name: { type: :string },marks: { '$ref' => '#/components/schemas/marks' },topic_id: { type: :integer },difficulty: { type: :integer },consistency: { type: :number },importances: { '$ref' => '#/components/schemas/importances' },proficiency: { type: :number },improvement_priorities: { '$ref' => '#/components/schemas/improvement_priorities' }}}},topics: {type: :array,items: {type: :object,properties: {id: { type: :integer },name: { type: :string },strand_id: { type: :integer },subtopics: { '$ref' => '#/components/schemas/subtopics' },difficulty: { type: :integer },consistency: { type: :number },importances: { '$ref' => '#/components/schemas/importances' },proficiency: { type: :number },improvement_priorities: { '$ref' => '#/components/schemas/improvement_priorities' }}}},strands: {type: :array,items: {type: :object,properties: {id: { type: :integer },name: { type: :string },topics: { '$ref' => '#/components/schemas/topics' }}}},latest_assessment: {type: :object,properties: {name: { type: :string },marks: { type: :integer },date_done: { type: :string },total_marks: { type: :integer }}},subjects: {type: :array,items: {type: :object,properties: {id: { type: :integer },name: { type: :string },target: { type: :integer },strands: { '$ref' => '#/components/schemas/strands' },latest_assessment: { '$ref' => '#/components/schemas/latest_assessment' },overall_proficiency: { type: :integer }}}},levels: {type: :array,items: {type: :object,properties: {id: { type: :integer },name: { type: :string },level: { type: :integer },subjects: { '$ref' => '#/components/schemas/subjects' }}}},student: {type: :object,properties: {id: { type: :integer },student_id: { type: :string },first_name: { type: :string },last_name: { type: :string },registration_date: { type: :string },school_id: { type: :integer },photo: {type: :object,properties: {url: { type: :string }}},overview_data: {type: :object,properties: {levels: { '$ref' => '#/components/schemas/levels' }}}}},detailed_subtopic: {type: :object,properties: {code: { type: :integer, default: 200 },message: { type: :string, default: 'ok' },data: { '$ref' => '#/components/schemas/partial_subtopic' },}},detailed_topic: {type: :object,properties: {code: { type: :integer, default: 200 },message: { type: :string, default: 'ok' },data: {type: :array,items: {type: :object,properties: {date: { type: :string },proficiency: { type: :number },contributions: { '$ref' => '#/components/schemas/partial_subtopic' },subtopic_id: { type: :integer },subtopic_name: { type: :string }}}}}},partial_subtopic: {type: :array,items: {type: :object,properties: {date: { type: :string },proficiency: { type: :number },contributions: {type: :array,items: {type: :object,properties: {score: { type: :number },worksheet: { type: :string },date: { type: :string }}}}}}}}}}}# Defaults to json. Accepts ':json' and ':yaml'.config.swagger_format = :json
end
 path '/api/v1/students/{id}' do# You'll want to customize the parameter types...parameter name: :'X-Admin-Authorization', in: :header, type: :string, required: false, default: 'sdfsd'parameter name: :page, in: :query, type: :integer, required: falseparameter name: 'id', in: :path, type: :integer, description: 'id'get('show student') dotags 'students'security [ bearer_auth: []]  # security [ Bearer: []]produces 'application/json'response '401', 'need login to create' dolet(:id) { 100 }run_test!endresponse(200, 'successful') doschema type: :object,properties: {code: { type: :integer, default: 200 },message: { type: :string, default: 'ok' },data: { '$ref' => '#/components/schemas/student' }}# let(:id) { '123' }# run_test!  # 运行测试xit  # 跳过测试用例endendend
end

http://www.ppmy.cn/news/948252.html

相关文章

win10如何设置pdf默认打开方式

win10如何设置pdf默认打开方式 1.首先,我们点击电脑左下角的微信按钮,弹出的界面,我们点击设置; 2.弹出的页面,我们点击应用; 3.我们点击默认应用,找到按文件类型指定默认应用; …

打开pdf文件目录的方法

并不是所有的pdf文件都是篇幅比较短,而且阅读起来是比较容易的。那么针对篇幅比较长的pdf文件如何阅读呢?一般情况下,是查看目录的,如何在pdf文件中查看目录呢? 分享下载网址:http://www.qingkuaipdf.com …

如何设置Adobe Acrobat DC为pdf的默认打开方式

如何设置Adobe Acrobat DC为pdf的默认打开方式 首先我们找到要打开的PDF文件--------> 右键pdf文件--------> 打开方式--------->选择其他应用 选择其他应用后就会弹出如下图的窗口:然后选择***Adobe Acrobat DC***-----> 勾选(始终使用此…

打开PDF格式文件的几种方式

PDF文件是一种高质量的文件,可以说是我们都比较喜欢的文件,喜欢的原因就是文件高质量还原。但是一些PDF文件很难在原始电脑上进行打开阅读,需要PDF编辑工具来对PDF文件进行打开。 1.直接打开PDF文件,下载好的迅捷PDF编辑器http://…

在vue中打开pdf文件

window.open(./static/xxx.pdf)

linux在命令行下打开pdf文件

1 linux在命令行下打开pdf文件 1.1 envice打开pdf文件 linux中一般使用envice命令打开pdf文件: envice filename.pdf 例如: evince how_to_use.pdf 1.2 可能遇到错误:evince: error while loading shared libraries: libz.so.1: failed to …

Android打开pdf文件

转https://www.jb51.net/article/136364.htm Android的WebView做不到ios的WebView那样可以很方便的直接预览pdf文件。要实现利用WebView预览pdf我们可以使用谷歌文档服务: mWebView.loadUrl("http://docs.google.com/gviewembeddedtrue&url" pdfUrl…

viewerjs 在html打开图片或打开pdf文件使用案例

开发者常用到在线访问pdf,txt,浏览图片的插件,这里推荐viewer.js这个插件,简单好用。它的核心亮点就是查看图片和pdf功能。老早以前就用过的,昨天一个小伙伴问我Android开发在线浏览pdf怎么弄?我一下想到这个插件&…