Class: FtrRuby::OpenAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(meta:) ⇒ OpenAPI

Returns a new instance of OpenAPI.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/openapi.rb', line 8

def initialize(meta:)
  indics = [meta[:indicators]] unless meta[:indicators].is_a? Array
  @testid = meta[:testid]
  @title = meta[:testname]
  @version = meta[:testversion]
  @metric = meta[:metric]
  @description = meta[:description]
  @indicator = indics.first
  @organization = meta[:organization]
  @org_url = meta[:org_url]
  @responsible_developer = meta[:responsible_developer]
  @email = meta[:email]
  @creator = meta[:creator]
  @host =  meta[:host]
  @host = @host.gsub(%r{/$}, "") # remove trailing slash if present
  @protocol =  meta[:protocol].gsub(%r{[:/]}, "")
  @basePath =  meta[:basePath].gsub(%r{[:/]}, "")
  @basePath = "/#{basePath}" unless basePath[0] == "/" # must start with a slash
  # @path = meta[:path]
  @response_description = meta[:response_description]
  @schemas = meta[:schemas]
  @endpointpath = "assess/test"
  # @end_url = "#{protocol}://#{host}#{basePath}/#{endpointpath}/#{testid}" # basepath starts with /
end

Instance Attribute Details

#basePathObject

Returns the value of attribute basePath.



3
4
5
# File 'lib/openapi.rb', line 3

def basePath
  @basePath
end

#creatorObject

Returns the value of attribute creator.



3
4
5
# File 'lib/openapi.rb', line 3

def creator
  @creator
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/openapi.rb', line 3

def description
  @description
end

#developer_ORCiDObject

Returns the value of attribute developer_ORCiD.



3
4
5
# File 'lib/openapi.rb', line 3

def developer_ORCiD
  @developer_ORCiD
end

#emailObject

Returns the value of attribute email.



3
4
5
# File 'lib/openapi.rb', line 3

def email
  @email
end

#endpointpathObject

Returns the value of attribute endpointpath.



3
4
5
# File 'lib/openapi.rb', line 3

def endpointpath
  @endpointpath
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/openapi.rb', line 3

def host
  @host
end

#indicatorObject

Returns the value of attribute indicator.



3
4
5
# File 'lib/openapi.rb', line 3

def indicator
  @indicator
end

#metricObject

Returns the value of attribute metric.



3
4
5
# File 'lib/openapi.rb', line 3

def metric
  @metric
end

#org_urlObject

Returns the value of attribute org_url.



3
4
5
# File 'lib/openapi.rb', line 3

def org_url
  @org_url
end

#organizationObject

Returns the value of attribute organization.



3
4
5
# File 'lib/openapi.rb', line 3

def organization
  @organization
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/openapi.rb', line 3

def path
  @path
end

#protocolObject

Returns the value of attribute protocol.



3
4
5
# File 'lib/openapi.rb', line 3

def protocol
  @protocol
end

#response_descriptionObject

Returns the value of attribute response_description.



3
4
5
# File 'lib/openapi.rb', line 3

def response_description
  @response_description
end

#responsible_developerObject

Returns the value of attribute responsible_developer.



3
4
5
# File 'lib/openapi.rb', line 3

def responsible_developer
  @responsible_developer
end

#schemasObject

Returns the value of attribute schemas.



3
4
5
# File 'lib/openapi.rb', line 3

def schemas
  @schemas
end

#testidObject

Returns the value of attribute testid.



3
4
5
# File 'lib/openapi.rb', line 3

def testid
  @testid
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/openapi.rb', line 3

def title
  @title
end

#versionObject

Returns the value of attribute version.



3
4
5
# File 'lib/openapi.rb', line 3

def version
  @version
end

Instance Method Details

#get_apiObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/openapi.rb', line 33

def get_api
  <<~"EOF_EOF"

    openapi: 3.0.0
    info:
      version: "#{version}"
      title: "#{title}"
      x-tests_metric: "#{metric}"
      description: >-
        #{description}
      x-applies_to_principle: "#{indicator}"
      contact:
        x-organization: "#{organization}"
        url: "#{org_url}"
        name: "#{responsible_developer}"
        x-role: responsible developer
        email: "#{email}"
        x-id: "#{creator}"
    paths:
      "/#{testid}":
        post:
          requestBody:
            content:
              application/json:
                schema:
                  $ref: "#/components/schemas/schemas"
            required: true
          responses:
            "200":
              description:  >-
                #{response_description}
    servers:
      - url: "#{protocol}://#{host}#{basePath}/#{endpointpath}"
    components:
      schemas:
        schemas:
          required:
            - resource_identifier
          properties:
            resource_identifier:
              type: string
              description: the GUID being tested

  EOF_EOF
end