• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

notEthan / scorpio / 13386829262

18 Feb 2025 08:59AM UTC coverage: 85.102%. Remained the same
13386829262

push

github

notEthan
Merge branches 'mv_openapi', 'google', 'test_resource_base', 'dev' and 'doc' into HEAD

133 of 175 new or added lines in 10 files covered. (76.0%)

72 existing lines in 6 files now uncovered.

1211 of 1423 relevant lines covered (85.1%)

383.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.38
/lib/scorpio/google_api_document.rb
1
# frozen_string_literal: true
2

3
module Scorpio
14✔
4
  module Google
14✔
5
    discovery_rest_description_doc = YAML.safe_load(Scorpio.root.join('documents/www.googleapis.com/discovery/v1/apis/discovery/v1/rest.yml').read)
14✔
6
    DISCOVERY_REST_DESCRIPTION = JSI::MetaSchemaNode.new(
14✔
7
      discovery_rest_description_doc,
8
      metaschema_root_ptr: JSI::Ptr['schemas']['JsonSchema'],
9
      root_schema_ptr: JSI::Ptr['schemas']['RestDescription'],
10
      schema_implementation_modules: [JSI::Schema::Draft04],
11
    )
12

13
    # naming these is not strictly necessary, but is nice to have.
14
    DirectoryList = DISCOVERY_REST_DESCRIPTION.schemas['DirectoryList'].jsi_schema_module
14✔
15
    JsonSchema     = DISCOVERY_REST_DESCRIPTION.schemas['JsonSchema'].jsi_schema_module
14✔
16
    RestDescription = DISCOVERY_REST_DESCRIPTION.schemas['RestDescription'].jsi_schema_module
14✔
17
    RestMethod     = DISCOVERY_REST_DESCRIPTION.schemas['RestMethod'].jsi_schema_module
14✔
18
    RestResource  = DISCOVERY_REST_DESCRIPTION.schemas['RestResource'].jsi_schema_module
14✔
19

20
    module RestDescription
14✔
21
      Resources = properties['resources']
14✔
22
    end
23

24
    module RestMethod
14✔
25
      Request = properties['request']
14✔
26
      Response = properties['response']
14✔
27

28
      # these only contain a $ref to a schema, but that is enough to use them as schemas
29
      Request.schema.describes_schema!([JSI::Schema::Draft04])
14✔
30
      Response.schema.describes_schema!([JSI::Schema::Draft04])
14✔
31
    end
32

33
    module HasMethodsAndResources
14✔
34
      def operations
14✔
NEW
35
        return @operations if instance_variable_defined?(:@operations)
×
NEW
36
        @operations = OpenAPI::OperationsScope.new(each_operation)
×
37
      end
38

39
      def each_operation(&block)
14✔
NEW
40
        return(to_enum(__method__)) unless block
×
41

NEW
42
        (self['methods'] || {}).each_value(&block)
×
43

NEW
44
        (self['resources'] || {}).each_value do |resource|
×
NEW
45
          resource.each_operation(&block)
×
46
        end
47
      end
48
    end
49

50
    module RestDescription
14✔
51
      include(OpenAPI::Document)
14✔
52
      include(HasMethodsAndResources)
14✔
53

54
      attr_writer(:base_url)
14✔
55

56
      def base_url(scheme: nil, server: nil, server_variables: nil)
14✔
NEW
57
        return @base_url if instance_variable_defined?(:@base_url)
×
NEW
58
        JSI::Util.uri(rootUrl ? File.join(rootUrl, servicePath) : baseUrl) # baseUrl is deprecated
×
59
      end
60

61
      def title
14✔
NEW
62
        self['title'] # override OpenAPI::Document#title
×
63
      end
64
    end
65

66
    module RestResource
14✔
67
      include(HasMethodsAndResources)
14✔
68
    end
69

70
    module RestMethod
14✔
71
      include(OpenAPI::Operation)
14✔
72

73
      def tagged?(tag_name)
14✔
NEW
74
        resource_names.include?(tag_name)
×
75
      end
76

77
      def resource_names
14✔
78
        # resource name is the property name where a RestResource is. kind of hax but it works.
NEW
79
        jsi_parent_nodes.select { |n| n.is_a?(RestResource) }.map { |r| r.jsi_ptr.tokens.last }
×
80
      end
81

82
      def path_template_str
14✔
NEW
83
        path
×
84
      end
85

86
      def parameters
14✔
NEW
87
        (self['parameters'] || {}).map do |name, schema|
×
NEW
88
          param = {'name' => name}
×
NEW
89
          param['in'] = schema.location if schema.key?('location')
×
NEW
90
          param['schema'] = schema
×
91
          #param['description'] = schema.description if schema.key?('description')
92
          #param['required'] = schema.required if schema.key?('required')
NEW
93
          param
×
94
        end
95
      end
96

97
      def request_media_type
14✔
NEW
98
        'application/json'
×
99
      end
100

101
      def http_method
14✔
NEW
102
        httpMethod
×
103
      end
104

105
      def openapi_document
14✔
NEW
106
        rest_description
×
107
      end
108

109
      def rest_description
14✔
NEW
110
        jsi_parent_nodes.detect { |p| p.is_a?(RestDescription) }
×
111
      end
112

113
      def scheme
14✔
114
        nil
115
      end
116

117
      def server
14✔
118
        nil
119
      end
120

121
      def server_variables
14✔
122
        nil
123
      end
124

125
      def operationId
14✔
NEW
126
        id
×
127
      end
128

129
      def request_schema
14✔
NEW
130
        request
×
131
      end
132

133
      def request_schemas
14✔
NEW
134
        request ? [request] : []
×
135
      end
136

137
      def response_schema(status: nil, media_type: nil)
14✔
NEW
138
        response
×
139
      end
140

141
      def response_schemas
14✔
NEW
142
        response ? [response] : []
×
143
      end
144
    end
145
  end
146
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc