diff --git a/app/json_schemas/json_api_schema.rb b/app/json_schemas/json_api_schema.rb index 9551becccc..069de6633d 100644 --- a/app/json_schemas/json_api_schema.rb +++ b/app/json_schemas/json_api_schema.rb @@ -90,10 +90,25 @@ class JsonApiSchema relationships: { type: :object, properties: relationships.to_h do |name| - [name, { "$ref" => "#/components/schemas/relationship" }] + [ + name, + relationship_schema(name) + ] end } } end + + def relationship_schema(name) + if is_singular?(name) + RelationshipSchema.schema(name) + else + RelationshipSchema.collection(name) + end + end + + def is_singular?(name) + name.to_s.singularize == name.to_s + end end end diff --git a/app/json_schemas/relationship_schema.rb b/app/json_schemas/relationship_schema.rb index 5b31dcf630..a223fd390f 100644 --- a/app/json_schemas/relationship_schema.rb +++ b/app/json_schemas/relationship_schema.rb @@ -1,12 +1,40 @@ # frozen_string_literal: true class RelationshipSchema - def self.schema + def self.schema(resource_name = nil) { type: :object, properties: { data: { - type: [:object, :array] + type: :object, + properties: { + id: { type: :string }, + type: { type: :string, example: resource_name } + } + }, + links: { + type: :object, + properties: { + related: { type: :string } + } + } + } + } + end + + def self.collection(resource_name = nil) + { + type: :object, + properties: { + data: { + type: :array, + items: { + type: :object, + properties: { + id: { type: :string }, + type: { type: :string, example: resource_name } + } + } }, links: { type: :object, diff --git a/swagger/v1/swagger.yaml b/swagger/v1/swagger.yaml index b18bed201d..9b2642959d 100644 --- a/swagger/v1/swagger.yaml +++ b/swagger/v1/swagger.yaml @@ -71,7 +71,21 @@ components: type: object properties: enterprise: - "$ref": "#/components/schemas/relationship" + type: object + properties: + data: + type: object + properties: + id: + type: string + type: + type: string + example: enterprise + links: + type: object + properties: + related: + type: string meta: type: object links: @@ -127,7 +141,21 @@ components: type: object properties: enterprise: - "$ref": "#/components/schemas/relationship" + type: object + properties: + data: + type: object + properties: + id: + type: string + type: + type: string + example: enterprise + links: + type: object + properties: + related: + type: string meta: type: object properties: