From 0f9a9c2bf1c4783155139ebb8124176faa0d1c81 Mon Sep 17 00:00:00 2001 From: Riin Fruit Date: Wed, 27 Jan 2021 15:38:51 +0900 Subject: [PATCH 1/4] fix invalid null type to nullable --- lib/rspec/openapi/schema_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rspec/openapi/schema_builder.rb b/lib/rspec/openapi/schema_builder.rb index fd16b6a6..9727c661 100644 --- a/lib/rspec/openapi/schema_builder.rb +++ b/lib/rspec/openapi/schema_builder.rb @@ -111,7 +111,7 @@ def build_type(value) when ActionDispatch::Http::UploadedFile { type: 'string', format: 'binary' } when NilClass - { type: 'null' } + { nullable: true } else raise NotImplementedError, "type detection is not implemented for: #{value.inspect}" end From f3b81db6fb6a67a34ab60155dc69ab968e25b957 Mon Sep 17 00:00:00 2001 From: Riin Fruit Date: Wed, 27 Jan 2021 15:39:13 +0900 Subject: [PATCH 2/4] spec: add test --- spec/rails/app/controllers/tables_controller.rb | 1 + spec/rails/doc/openapi.yaml | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/spec/rails/app/controllers/tables_controller.rb b/spec/rails/app/controllers/tables_controller.rb index 737dbca9..dbe482ea 100644 --- a/spec/rails/app/controllers/tables_controller.rb +++ b/spec/rails/app/controllers/tables_controller.rb @@ -47,6 +47,7 @@ def find_table(id = nil) id: 2, name: 'production', }, + null_sample: nil, storage_size: 12.3, created_at: time.iso8601, updated_at: time.iso8601, diff --git a/spec/rails/doc/openapi.yaml b/spec/rails/doc/openapi.yaml index 362ff46c..c423d1a8 100644 --- a/spec/rails/doc/openapi.yaml +++ b/spec/rails/doc/openapi.yaml @@ -47,6 +47,8 @@ paths: type: integer name: type: string + null_sample: + nullable: true storage_size: type: number format: float @@ -61,6 +63,7 @@ paths: database: id: 2 name: production + null_sample: storage_size: 12.3 created_at: '2020-07-17T00:00:00+00:00' updated_at: '2020-07-17T00:00:00+00:00' @@ -116,6 +119,8 @@ paths: type: integer name: type: string + null_sample: + nullable: true storage_size: type: number format: float @@ -130,6 +135,7 @@ paths: database: id: 2 name: production + null_sample: storage_size: 12.3 created_at: '2020-07-17T00:00:00+00:00' updated_at: '2020-07-17T00:00:00+00:00' @@ -166,6 +172,8 @@ paths: type: integer name: type: string + null_sample: + nullable: true storage_size: type: number format: float @@ -180,6 +188,7 @@ paths: database: id: 2 name: production + null_sample: storage_size: 12.3 created_at: '2020-07-17T00:00:00+00:00' updated_at: '2020-07-17T00:00:00+00:00' @@ -229,7 +238,7 @@ paths: image: !ruby/object:ActionDispatch::Http::UploadedFile tempfile: !ruby/object:Tempfile unlinked: true - mode: 194 + mode: 2562 tmpfile: &1 !ruby/object:File {} opts: :perm: 384 @@ -259,6 +268,8 @@ paths: type: integer name: type: string + null_sample: + nullable: true storage_size: type: number format: float @@ -273,6 +284,7 @@ paths: database: id: 2 name: production + null_sample: storage_size: 12.3 created_at: '2020-07-17T00:00:00+00:00' updated_at: '2020-07-17T00:00:00+00:00' @@ -308,6 +320,8 @@ paths: type: integer name: type: string + null_sample: + nullable: true storage_size: type: number format: float @@ -322,6 +336,7 @@ paths: database: id: 2 name: production + null_sample: storage_size: 12.3 created_at: '2020-07-17T00:00:00+00:00' updated_at: '2020-07-17T00:00:00+00:00' From 588e4240e5262ba15a36293554377c7566111de6 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Tue, 26 Jan 2021 23:52:41 -0800 Subject: [PATCH 3/4] Fix test examples --- spec/rails/doc/openapi.yaml | 122 ++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/spec/rails/doc/openapi.yaml b/spec/rails/doc/openapi.yaml index 3901d33a..27ebdd61 100644 --- a/spec/rails/doc/openapi.yaml +++ b/spec/rails/doc/openapi.yaml @@ -12,20 +12,20 @@ paths: get: summary: index tags: - - Table + - Table parameters: - - name: page - in: query - schema: - type: integer - example: 1 - - name: per - in: query - schema: - type: integer - example: 10 + - name: page + in: query + schema: + type: integer + example: 1 + - name: per + in: query + schema: + type: integer + example: 10 responses: - "200": + '200': description: returns a list of tables content: application/json: @@ -57,17 +57,17 @@ paths: updated_at: type: string example: - - id: 1 - name: access - description: logs - database: - id: 2 - name: production - null_sample: - storage_size: 12.3 - created_at: "2020-07-17T00:00:00+00:00" - updated_at: "2020-07-17T00:00:00+00:00" - "401": + - id: 1 + name: access + description: logs + database: + id: 2 + name: production + null_sample: + storage_size: 12.3 + created_at: '2020-07-17T00:00:00+00:00' + updated_at: '2020-07-17T00:00:00+00:00' + '401': description: does not return tables if unauthorized content: application/json: @@ -81,7 +81,7 @@ paths: post: summary: create tags: - - Table + - Table requestBody: content: application/json: @@ -99,7 +99,7 @@ paths: description: description database_id: 2 responses: - "201": + '201': description: returns a table content: application/json: @@ -137,22 +137,22 @@ paths: name: production null_sample: storage_size: 12.3 - created_at: "2020-07-17T00:00:00+00:00" - updated_at: "2020-07-17T00:00:00+00:00" + created_at: '2020-07-17T00:00:00+00:00' + updated_at: '2020-07-17T00:00:00+00:00' "/tables/{id}": get: summary: show tags: - - Table + - Table parameters: - - name: id - in: path - required: true - schema: - type: integer - example: 1 + - name: id + in: path + required: true + schema: + type: integer + example: 1 responses: - "200": + '200': description: returns a table content: application/json: @@ -190,9 +190,9 @@ paths: name: production null_sample: storage_size: 12.3 - created_at: "2020-07-17T00:00:00+00:00" - updated_at: "2020-07-17T00:00:00+00:00" - "401": + created_at: '2020-07-17T00:00:00+00:00' + updated_at: '2020-07-17T00:00:00+00:00' + '401': description: does not return a table if unauthorized content: application/json: @@ -203,7 +203,7 @@ paths: type: string example: message: Unauthorized - "404": + '404': description: does not return a table if not found content: application/json: @@ -217,14 +217,14 @@ paths: patch: summary: update tags: - - Table + - Table parameters: - - name: id - in: path - required: true - schema: - type: integer - example: 1 + - name: id + in: path + required: true + schema: + type: integer + example: 1 requestBody: content: multipart/form-data: @@ -237,7 +237,7 @@ paths: example: image: test.png responses: - "200": + '200': description: returns a table content: application/json: @@ -275,21 +275,21 @@ paths: name: production null_sample: storage_size: 12.3 - created_at: "2020-07-17T00:00:00+00:00" - updated_at: "2020-07-17T00:00:00+00:00" + created_at: '2020-07-17T00:00:00+00:00' + updated_at: '2020-07-17T00:00:00+00:00' delete: summary: destroy tags: - - Table + - Table parameters: - - name: id - in: path - required: true - schema: - type: integer - example: 1 + - name: id + in: path + required: true + schema: + type: integer + example: 1 responses: - "200": + '200': description: returns a table content: application/json: @@ -327,9 +327,9 @@ paths: name: production null_sample: storage_size: 12.3 - created_at: "2020-07-17T00:00:00+00:00" - updated_at: "2020-07-17T00:00:00+00:00" - "202": + created_at: '2020-07-17T00:00:00+00:00' + updated_at: '2020-07-17T00:00:00+00:00' + '202': description: returns no content if specified requestBody: content: @@ -340,4 +340,4 @@ paths: no_content: type: string example: - no_content: "true" + no_content: 'true' From b575ac3a0b942c310de9590eda6f629af5c2588c Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Tue, 26 Jan 2021 23:55:25 -0800 Subject: [PATCH 4/4] Add trailing spaces --- spec/rails/doc/openapi.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/rails/doc/openapi.yaml b/spec/rails/doc/openapi.yaml index 27ebdd61..67634be8 100644 --- a/spec/rails/doc/openapi.yaml +++ b/spec/rails/doc/openapi.yaml @@ -63,7 +63,7 @@ paths: database: id: 2 name: production - null_sample: + null_sample: storage_size: 12.3 created_at: '2020-07-17T00:00:00+00:00' updated_at: '2020-07-17T00:00:00+00:00' @@ -135,7 +135,7 @@ paths: database: id: 2 name: production - null_sample: + null_sample: storage_size: 12.3 created_at: '2020-07-17T00:00:00+00:00' updated_at: '2020-07-17T00:00:00+00:00' @@ -188,7 +188,7 @@ paths: database: id: 2 name: production - null_sample: + null_sample: storage_size: 12.3 created_at: '2020-07-17T00:00:00+00:00' updated_at: '2020-07-17T00:00:00+00:00' @@ -273,7 +273,7 @@ paths: database: id: 2 name: production - null_sample: + null_sample: storage_size: 12.3 created_at: '2020-07-17T00:00:00+00:00' updated_at: '2020-07-17T00:00:00+00:00' @@ -325,7 +325,7 @@ paths: database: id: 2 name: production - null_sample: + null_sample: storage_size: 12.3 created_at: '2020-07-17T00:00:00+00:00' updated_at: '2020-07-17T00:00:00+00:00'