mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
12
spec/requests/api/schemas/json/tag_group_create_request.json
Normal file
12
spec/requests/api/schemas/json/tag_group_create_request.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name"
|
||||
]
|
||||
}
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
18
spec/requests/api/schemas/schema_loader.rb
Normal file
18
spec/requests/api/schemas/schema_loader.rb
Normal 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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user