DEV: Updates to api docs schema validation (#11801)

- Read in schemas from actual json files instead of a ruby hash. This is
helpful because we will be automatically generating .json schema files
from json responses and don't want to manually write ruby hash schema
files.

- Create a helper method for rspec schema validation tests to dry up code
This commit is contained in:
Blake Erickson
2021-01-21 18:23:23 -07:00
committed by GitHub
parent 7434116933
commit c889b676f8
6 changed files with 99 additions and 95 deletions

View File

@@ -0,0 +1,12 @@
{
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
}
},
"required": [
"name"
]
}

View File

@@ -0,0 +1,51 @@
{
"type": "object",
"additionalProperties": false,
"properties": {
"tag_group": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"tag_names": {
"type": "array",
"items": [
]
},
"parent_tag_name": {
"type": "array",
"items": [
]
},
"one_per_topic": {
"type": "boolean"
},
"permissions": {
"type": "object",
"properties": {
"everyone": {
"type": "integer"
}
}
}
},
"required": [
"id",
"name",
"tag_names",
"parent_tag_name",
"one_per_topic",
"permissions"
]
}
},
"required": [
"tag_group"
]
}

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
require 'json'
module SpecSchemas
class SpecLoader
def initialize(filename)
@filename = filename
end
def load
JSON.parse(File.read(File.join(__dir__, "json", "#{@filename}.json")))
end
end
end

View File

@@ -1,77 +0,0 @@
# frozen_string_literal: true
module SpecSchemas
class TagGroupCreateRequest
def schemer
schema = {
'type' => 'object',
'additionalProperties' => false,
'properties' => {
'name' => {
'type' => 'string',
}
},
'required' => ['name']
}
end
end
class TagGroupResponse
def schemer
schema = {
'type' => 'object',
'additionalProperties' => false,
'properties' => {
'tag_group' => {
'type' => 'object',
'properties' => {
'id' => {
'type' => 'integer',
},
'name' => {
'type' => 'string',
},
'tag_names' => {
'type' => 'array',
'items' => {
'type' => 'string'
}
},
'parent_tag_name' => {
'type' => 'array',
'items' => {
'type' => 'string'
}
},
'one_per_topic' => {
'type' => 'boolean',
},
'permissions' => {
'type' => 'object',
'properties' => {
'everyone' => {
'type' => 'integer',
'example' => 1
}
}
}
},
'required' => [
'id',
'name',
'tag_names',
'parent_tag_name',
'one_per_topic',
'permissions'
]
}
},
'required' => [
'tag_group'
]
}
end
end
end