|
1 | 1 | require 'spec_dsl'
|
2 | 2 |
|
| 3 | +def clear |
| 4 | + after_do { @doc_info[:components] = { } } |
| 5 | +end |
| 6 | + |
3 | 7 | RSpec.describe OpenApi::DSL::Components do
|
4 | 8 | get_and_dig_doc [:components]
|
5 | 9 | let(:dsl_in) { [:components] }
|
6 | 10 |
|
7 | 11 | desc :schema, subject: :schemas do
|
8 | 12 | correct do
|
9 |
| - mk -> { schema :SchemaA, String; schema :SchemaZ, String }, doc_will_has_keys: { schemas: %i[ SchemaA SchemaZ ] } |
| 13 | + mk -> { schema :SchemaA, String; schema :SchemaZ, String }, doc_will_has_keys: { schemas: %i[ SchemaA SchemaZ ] }; clear |
10 | 14 |
|
11 |
| - mk -> { schema :SchemaA, String }, get: { SchemaA: { type: 'string'} } |
12 |
| - mk -> { schema :SchemaA, type: Integer }, get: { SchemaA: { type: 'integer'} } |
13 |
| - mk -> { schema :SchemaB => [ String ] }, get: { SchemaB: { type: 'string'} } |
14 |
| - mk -> { schema :SchemaC => [ type: String, desc: 'test' ] }, get: { SchemaC: { type: 'string', description: 'test' } } |
| 15 | + mk -> { schema :SchemaA, String }, get: { SchemaA: { type: 'string'} }; clear |
| 16 | + mk -> { schema :SchemaA, type: Integer }, get: { SchemaA: { type: 'integer'} }; clear |
| 17 | + mk -> { schema :SchemaB => [ String ] }, get: { SchemaB: { type: 'string'} }; clear |
| 18 | + mk -> { schema :SchemaC => [ type: String, desc: 'test' ] }, get: { SchemaC: { type: 'string', description: 'test' } }; clear |
15 | 19 |
|
16 | 20 | context 'when defining combined schema' do
|
17 | 21 | mk -> { schema :SchemaD => [ one_of: [String] ] }, has_keys: { SchemaD: [:oneOf] }
|
|
25 | 29 |
|
26 | 30 |
|
27 | 31 | desc :example, subject: :examples do
|
28 |
| - mk -> { example :ExampleA, { }; example :ExampleZ, { } }, doc_will_has_keys: { examples: %i[ ExampleA ExampleZ ] } |
| 32 | + mk -> { example :ExampleA, { }; example :ExampleZ, { } }, doc_will_has_keys: { examples: %i[ ExampleA ExampleZ ] }; clear |
29 | 33 | mk -> { example :ExampleA, { name: 'BeiGou' } }, get: { ExampleA: [{ name: { value: 'BeiGou' } }] }
|
30 | 34 | end
|
31 | 35 |
|
|
43 | 47 | expect_its :name, eq: :page
|
44 | 48 | expect_its :in, eq: 'query'
|
45 | 49 | expect_its :required, eq: false
|
46 |
| - expect_its :schema, eq: { type: 'integer' } |
| 50 | + expect_its :schema, eq: { type: 'integer' }; clear |
47 | 51 |
|
48 | 52 | mk -> { path :PathId => [ :id, Integer ] }, has_keys: { PathId: its_structure << { schema: [:type] } }
|
49 | 53 |
|
|
107 | 111 | mk -> do
|
108 | 112 | response :RespA, 'invalid token'
|
109 | 113 | response :RespZ, 'parameter validation failed'
|
110 |
| - end, doc_will_has_keys: { responses: %i[ RespA RespZ ] } |
| 114 | + end, doc_will_has_keys: { responses: %i[ RespA RespZ ] }; clear |
111 | 115 |
|
112 | 116 | mk -> { resp :RespA => [ 'desc', :json ] }, has_keys!: { RespA: its_structure }
|
113 | 117 | focus_on :RespA
|
|
124 | 128 | authorizationUrl: 'https://example.com/api/oauth/dialog',
|
125 | 129 | scopes: { 'write:pets': 'modify pets in your account', 'read:pets': 'read your pets' }
|
126 | 130 | } }, desc: 'desc'
|
127 |
| - end, doc_will_has_keys: { securitySchemes: %i[ OAuth ] } |
| 131 | + end, doc_will_has_keys: { securitySchemes: %i[ OAuth ] }; clear |
128 | 132 |
|
129 | 133 | describe '#base_auth' do
|
130 |
| - mk -> { base_auth :BaseAuth }, get: { BaseAuth: { type: 'http', scheme: 'basic' }} |
| 134 | + mk -> { base_auth :BaseAuth }, get: { BaseAuth: { type: 'http', scheme: 'basic' } }; clear |
131 | 135 | end
|
132 | 136 |
|
133 | 137 | describe '#bearer_auth' do
|
134 |
| - mk -> { bearer_auth :Token }, get: { Token: { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }} |
| 138 | + mk -> { bearer_auth :Token }, get: { Token: { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' } }; clear |
135 | 139 | end
|
136 | 140 |
|
137 | 141 | describe '#api_key' do
|
|
0 commit comments