brainstem 1.4.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +77 -0
- data/README.md +119 -0
- data/docs/api_doc_generator.markdown +45 -4
- data/docs/brainstem_executable.markdown +1 -1
- data/docs/oas_2_docgen.png +0 -0
- data/docs/oas_2_docgen_ascii.txt +78 -0
- data/lib/brainstem/api_docs.rb +23 -9
- data/lib/brainstem/api_docs/abstract_collection.rb +0 -13
- data/lib/brainstem/api_docs/atlas.rb +0 -14
- data/lib/brainstem/api_docs/builder.rb +0 -14
- data/lib/brainstem/api_docs/controller.rb +7 -16
- data/lib/brainstem/api_docs/controller_collection.rb +0 -3
- data/lib/brainstem/api_docs/endpoint.rb +73 -19
- data/lib/brainstem/api_docs/endpoint_collection.rb +0 -7
- data/lib/brainstem/api_docs/formatters/abstract_formatter.rb +0 -2
- data/lib/brainstem/api_docs/formatters/markdown/controller_formatter.rb +1 -9
- data/lib/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter.rb +1 -9
- data/lib/brainstem/api_docs/formatters/markdown/endpoint_formatter.rb +39 -24
- data/lib/brainstem/api_docs/formatters/markdown/helper.rb +0 -13
- data/lib/brainstem/api_docs/formatters/markdown/presenter_formatter.rb +22 -35
- data/lib/brainstem/api_docs/formatters/open_api_specification/helper.rb +66 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/controller_formatter.rb +57 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint/param_definitions_formatter.rb +311 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint/response_definitions_formatter.rb +197 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint_collection_formatter.rb +60 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint_formatter.rb +162 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/info_formatter.rb +126 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/presenter_formatter.rb +132 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/security_definitions_formatter.rb +99 -0
- data/lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb +123 -0
- data/lib/brainstem/api_docs/introspectors/abstract_introspector.rb +0 -7
- data/lib/brainstem/api_docs/introspectors/rails_introspector.rb +1 -20
- data/lib/brainstem/api_docs/presenter.rb +21 -27
- data/lib/brainstem/api_docs/presenter_collection.rb +1 -11
- data/lib/brainstem/api_docs/resolver.rb +1 -8
- data/lib/brainstem/api_docs/sinks/abstract_sink.rb +0 -4
- data/lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb +0 -9
- data/lib/brainstem/api_docs/sinks/open_api_specification_sink.rb +234 -0
- data/lib/brainstem/api_docs/sinks/stdout_sink.rb +0 -5
- data/lib/brainstem/cli.rb +0 -13
- data/lib/brainstem/cli/abstract_command.rb +0 -7
- data/lib/brainstem/cli/generate_api_docs_command.rb +48 -24
- data/lib/brainstem/concerns/controller_dsl.rb +288 -145
- data/lib/brainstem/concerns/formattable.rb +0 -5
- data/lib/brainstem/concerns/optional.rb +0 -1
- data/lib/brainstem/concerns/presenter_dsl.rb +2 -21
- data/lib/brainstem/dsl/configuration.rb +0 -11
- data/lib/brainstem/presenter.rb +0 -4
- data/lib/brainstem/version.rb +1 -1
- data/spec/brainstem/api_docs/abstract_collection_spec.rb +0 -11
- data/spec/brainstem/api_docs/atlas_spec.rb +0 -6
- data/spec/brainstem/api_docs/builder_spec.rb +0 -4
- data/spec/brainstem/api_docs/controller_collection_spec.rb +0 -2
- data/spec/brainstem/api_docs/controller_spec.rb +29 -18
- data/spec/brainstem/api_docs/endpoint_collection_spec.rb +0 -6
- data/spec/brainstem/api_docs/endpoint_spec.rb +343 -13
- data/spec/brainstem/api_docs/formatters/abstract_formatter_spec.rb +0 -2
- data/spec/brainstem/api_docs/formatters/markdown/controller_formatter_spec.rb +0 -1
- data/spec/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter_spec.rb +0 -5
- data/spec/brainstem/api_docs/formatters/markdown/endpoint_formatter_spec.rb +94 -8
- data/spec/brainstem/api_docs/formatters/markdown/helper_spec.rb +0 -8
- data/spec/brainstem/api_docs/formatters/markdown/presenter_formatter_spec.rb +0 -7
- data/spec/brainstem/api_docs/formatters/open_api_specification/helper_spec.rb +210 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/controller_formatter_spec.rb +81 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint/param_definitions_formatter_spec.rb +672 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint/response_definitions_formatter_spec.rb +335 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint_collection_formatter_spec.rb +59 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint_formatter_spec.rb +308 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/info_formatter_spec.rb +89 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/presenter_formatter_spec.rb +430 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/security_definitions_formatter_spec.rb +190 -0
- data/spec/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter_spec.rb +217 -0
- data/spec/brainstem/api_docs/introspectors/abstract_introspector_spec.rb +0 -2
- data/spec/brainstem/api_docs/introspectors/rails_introspector_spec.rb +0 -2
- data/spec/brainstem/api_docs/presenter_collection_spec.rb +0 -2
- data/spec/brainstem/api_docs/presenter_spec.rb +58 -18
- data/spec/brainstem/api_docs/resolver_spec.rb +0 -1
- data/spec/brainstem/api_docs/sinks/controller_presenter_multifile_sink_spec.rb +0 -2
- data/spec/brainstem/api_docs/sinks/open_api_specification_sink_spec.rb +371 -0
- data/spec/brainstem/api_docs_spec.rb +2 -0
- data/spec/brainstem/cli/abstract_command_spec.rb +0 -4
- data/spec/brainstem/cli/generate_api_docs_command_spec.rb +53 -2
- data/spec/brainstem/concerns/controller_dsl_spec.rb +430 -64
- data/spec/brainstem/concerns/presenter_dsl_spec.rb +0 -20
- data/spec/brainstem/preloader_spec.rb +0 -7
- data/spec/brainstem/presenter_spec.rb +0 -1
- data/spec/dummy/rails.rb +0 -1
- data/spec/spec_helpers/db.rb +0 -1
- metadata +37 -2
@@ -7,7 +7,6 @@ module Brainstem
|
|
7
7
|
let(:options) { { } }
|
8
8
|
subject { AbstractCommand.new(options) }
|
9
9
|
|
10
|
-
|
11
10
|
describe ".call" do
|
12
11
|
before do
|
13
12
|
any_instance_of(AbstractCommand) do |instance|
|
@@ -41,7 +40,6 @@ module Brainstem
|
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
44
|
-
|
45
43
|
describe "#extract_options!" do
|
46
44
|
let(:option_parser) { Object.new }
|
47
45
|
let(:args) { %w(--silent --pretend) }
|
@@ -57,14 +55,12 @@ module Brainstem
|
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
60
|
-
|
61
58
|
describe "#option_parser" do
|
62
59
|
it "is not implemented" do
|
63
60
|
expect { AbstractCommand.new }.to raise_error NotImplementedError
|
64
61
|
end
|
65
62
|
end
|
66
63
|
|
67
|
-
|
68
64
|
describe "#initialize" do
|
69
65
|
it "extracts options from args" do
|
70
66
|
any_instance_of(AbstractCommand) do |instance|
|
@@ -31,6 +31,14 @@ module Brainstem
|
|
31
31
|
expect(subject.options[:sink][:method].call).to be_a \
|
32
32
|
Brainstem::ApiDocs::Sinks::ControllerPresenterMultifileSink
|
33
33
|
end
|
34
|
+
|
35
|
+
context "when format is Open API Specification" do
|
36
|
+
let(:args) { %w(--open-api-specification=2 --multifile-presenters-and-controllers) }
|
37
|
+
|
38
|
+
it "raises an error" do
|
39
|
+
expect { subject }.to raise_error(NotImplementedError)
|
40
|
+
end
|
41
|
+
end
|
34
42
|
end
|
35
43
|
|
36
44
|
context "when --base-application-class" do
|
@@ -50,6 +58,14 @@ module Brainstem
|
|
50
58
|
end
|
51
59
|
end
|
52
60
|
|
61
|
+
context "when --api-version" do
|
62
|
+
let(:args) { %w(--api-version=2.0.0) }
|
63
|
+
|
64
|
+
it "sets the api version option of the sink" do
|
65
|
+
expect(subject.options[:sink][:options][:api_version]).to eq '2.0.0'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
53
69
|
context "when --controller-matches" do
|
54
70
|
let(:matches) { subject.options[:builder][:args_for_atlas][:controller_matches] }
|
55
71
|
|
@@ -73,8 +89,44 @@ module Brainstem
|
|
73
89
|
end
|
74
90
|
end
|
75
91
|
end
|
76
|
-
end
|
77
92
|
|
93
|
+
context "when --open-api-specification" do
|
94
|
+
context "when the correct version is specified" do
|
95
|
+
let(:args) { %w(--open-api-specification=2) }
|
96
|
+
|
97
|
+
it "sets sink to OpenApiSpecificationSink and format to oas_v2" do
|
98
|
+
expect(subject.options).to have_key :sink
|
99
|
+
expect(subject.options[:sink][:options][:format]).to eq(:oas_v2)
|
100
|
+
expect(subject.options[:sink][:method].call).to be_a \
|
101
|
+
Brainstem::ApiDocs::Sinks::OpenApiSpecificationSink
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "when the incorrect version is specified" do
|
106
|
+
let(:args) { %w(--open-api-specification=3) }
|
107
|
+
|
108
|
+
it "raises a Not Implemented Error" do
|
109
|
+
expect { subject }.to raise_error(NotImplementedError)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "when --output-extension" do
|
115
|
+
let(:args) { %w(--output-extension=yml) }
|
116
|
+
|
117
|
+
it "sets the api version option of the sink" do
|
118
|
+
expect(subject.options[:sink][:options][:output_extension]).to eq 'yml'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when --oas-filename-pattern" do
|
123
|
+
let(:args) { %w(--oas-filename-pattern=blah/{{version}}.{{extension}}) }
|
124
|
+
|
125
|
+
it "sets the api version option of the sink" do
|
126
|
+
expect(subject.options[:sink][:options][:oas_filename_pattern]).to eq 'blah/{{version}}.{{extension}}'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
78
130
|
|
79
131
|
describe "execution" do
|
80
132
|
context "when no sink provided" do
|
@@ -128,7 +180,6 @@ module Brainstem
|
|
128
180
|
end
|
129
181
|
end
|
130
182
|
end
|
131
|
-
|
132
183
|
end
|
133
184
|
end
|
134
185
|
end
|
@@ -101,6 +101,58 @@ module Brainstem
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
+
describe ".tag" do
|
105
|
+
it "sets the tag for the context" do
|
106
|
+
subject.brainstem_params do
|
107
|
+
tag "TagName"
|
108
|
+
end
|
109
|
+
|
110
|
+
expect(subject.configuration[:_default][:tag]).to eq "TagName"
|
111
|
+
end
|
112
|
+
|
113
|
+
context "when used in an action" do
|
114
|
+
it "raises and error" do
|
115
|
+
expect {
|
116
|
+
subject.brainstem_params do
|
117
|
+
actions :show do
|
118
|
+
tag "TagName"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
}.to raise_error(StandardError)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe ".tag_groups" do
|
127
|
+
it "sets the tag groups" do
|
128
|
+
subject.brainstem_params do
|
129
|
+
tag_groups "Group Tag 1"
|
130
|
+
end
|
131
|
+
|
132
|
+
expect(subject.configuration[:_default][:tag_groups]).to eq ["Group Tag 1"]
|
133
|
+
end
|
134
|
+
|
135
|
+
it "sets the tag groups when an array is given" do
|
136
|
+
subject.brainstem_params do
|
137
|
+
tag_groups ["Group Tag 1", "Group Tag 2"]
|
138
|
+
end
|
139
|
+
|
140
|
+
expect(subject.configuration[:_default][:tag_groups]).to eq ["Group Tag 1", "Group Tag 2"]
|
141
|
+
end
|
142
|
+
|
143
|
+
context "when used in an action" do
|
144
|
+
it "raises and error" do
|
145
|
+
expect {
|
146
|
+
subject.brainstem_params do
|
147
|
+
actions :show do
|
148
|
+
tag_groups ["Group Tag 1", "Group Tag 2"]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
}.to raise_error(StandardError)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
104
156
|
describe ".model_params" do
|
105
157
|
let(:root_proc) { Proc.new {} }
|
106
158
|
|
@@ -472,70 +524,6 @@ module Brainstem
|
|
472
524
|
end
|
473
525
|
end
|
474
526
|
end
|
475
|
-
|
476
|
-
context "deprecated type behavior" do
|
477
|
-
context "when no type is provided" do
|
478
|
-
before do
|
479
|
-
mock(subject).deprecated_type_warning
|
480
|
-
end
|
481
|
-
|
482
|
-
it "defaults to type string" do
|
483
|
-
subject.brainstem_params do
|
484
|
-
valid :sprocket_name, required: true
|
485
|
-
end
|
486
|
-
|
487
|
-
valid_params = subject.configuration[:_default][:valid_params]
|
488
|
-
expect(valid_params.keys.length).to eq(1)
|
489
|
-
expect(valid_params.keys[0].call).to eq("sprocket_name")
|
490
|
-
|
491
|
-
configuration = valid_params[valid_params.keys[0]]
|
492
|
-
expect(configuration[:type]).to eq("string")
|
493
|
-
expect(configuration[:required]).to be_truthy
|
494
|
-
end
|
495
|
-
end
|
496
|
-
|
497
|
-
context "when no type and options are provided" do
|
498
|
-
before do
|
499
|
-
mock(subject).deprecated_type_warning
|
500
|
-
end
|
501
|
-
|
502
|
-
it "defaults type to string and sets default options for the param" do
|
503
|
-
subject.brainstem_params do
|
504
|
-
valid :sprocket_name
|
505
|
-
end
|
506
|
-
|
507
|
-
valid_params = subject.configuration[:_default][:valid_params]
|
508
|
-
expect(valid_params.keys.length).to eq(1)
|
509
|
-
expect(valid_params.keys[0].call).to eq("sprocket_name")
|
510
|
-
|
511
|
-
configuration = valid_params[valid_params.keys[0]]
|
512
|
-
expect(configuration[:nodoc]).to be_falsey
|
513
|
-
expect(configuration[:required]).to be_falsey
|
514
|
-
expect(configuration[:type]).to eq("string")
|
515
|
-
end
|
516
|
-
end
|
517
|
-
|
518
|
-
context "when type and options are hashes" do
|
519
|
-
before do
|
520
|
-
mock(subject).deprecated_type_warning
|
521
|
-
end
|
522
|
-
|
523
|
-
it "ignores the type and defaults to string" do
|
524
|
-
subject.brainstem_params do
|
525
|
-
valid :sprocket_name, { troll: true }, { required: true }
|
526
|
-
end
|
527
|
-
|
528
|
-
valid_params = subject.configuration[:_default][:valid_params]
|
529
|
-
expect(valid_params.keys.length).to eq(1)
|
530
|
-
expect(valid_params.keys[0].call).to eq("sprocket_name")
|
531
|
-
|
532
|
-
configuration = valid_params[valid_params.keys[0]]
|
533
|
-
expect(configuration[:nodoc]).to be_falsey
|
534
|
-
expect(configuration[:required]).to be_truthy
|
535
|
-
expect(configuration[:type]).to eq("string")
|
536
|
-
end
|
537
|
-
end
|
538
|
-
end
|
539
527
|
end
|
540
528
|
|
541
529
|
describe ".transform" do
|
@@ -713,6 +701,384 @@ module Brainstem
|
|
713
701
|
end
|
714
702
|
end
|
715
703
|
|
704
|
+
describe ".response" do
|
705
|
+
context "when block given" do
|
706
|
+
it "sets the custom_response configuration" do
|
707
|
+
subject.brainstem_params do
|
708
|
+
actions :show do
|
709
|
+
response :array do |response_param|
|
710
|
+
response_param.field :blah, :string
|
711
|
+
end
|
712
|
+
end
|
713
|
+
end
|
714
|
+
|
715
|
+
configuration = subject.configuration[:show][:custom_response]
|
716
|
+
expect(configuration).to be_present
|
717
|
+
expect(configuration[:_config]).to eq({
|
718
|
+
type: 'array',
|
719
|
+
item_type: 'hash',
|
720
|
+
nodoc: false,
|
721
|
+
required: false,
|
722
|
+
}.with_indifferent_access)
|
723
|
+
end
|
724
|
+
end
|
725
|
+
|
726
|
+
context "when block not given" do
|
727
|
+
it "sets the custom_response configuration" do
|
728
|
+
subject.brainstem_params do
|
729
|
+
actions :show do
|
730
|
+
response :array
|
731
|
+
end
|
732
|
+
end
|
733
|
+
|
734
|
+
configuration = subject.configuration[:show][:custom_response]
|
735
|
+
expect(configuration).to be_present
|
736
|
+
expect(configuration[:_config]).to eq({
|
737
|
+
type: 'array',
|
738
|
+
item_type: 'string',
|
739
|
+
nodoc: false,
|
740
|
+
required: false,
|
741
|
+
}.with_indifferent_access)
|
742
|
+
end
|
743
|
+
end
|
744
|
+
end
|
745
|
+
|
746
|
+
describe ".fields" do
|
747
|
+
context "when used outside of the response block" do
|
748
|
+
it "raises an error" do
|
749
|
+
expect {
|
750
|
+
subject.brainstem_params do
|
751
|
+
actions :show do
|
752
|
+
fields :contacts, :array do
|
753
|
+
field :full_name, :string
|
754
|
+
end
|
755
|
+
end
|
756
|
+
end
|
757
|
+
}.to raise_error(StandardError)
|
758
|
+
end
|
759
|
+
end
|
760
|
+
|
761
|
+
context "when used within the response block" do
|
762
|
+
context "when type is hash" do
|
763
|
+
it "adds the field block to custom_response configuration" do
|
764
|
+
subject.brainstem_params do
|
765
|
+
actions :show do
|
766
|
+
response :hash do
|
767
|
+
fields :contact, :hash do
|
768
|
+
field :full_name, :string
|
769
|
+
end
|
770
|
+
end
|
771
|
+
end
|
772
|
+
end
|
773
|
+
|
774
|
+
configuration = subject.configuration[:show][:custom_response]
|
775
|
+
param_keys = configuration.keys
|
776
|
+
|
777
|
+
expect(param_keys[1].call).to eq('contact')
|
778
|
+
expect(configuration[param_keys[1]]).to eq({
|
779
|
+
type: 'hash',
|
780
|
+
nodoc: false,
|
781
|
+
required: false,
|
782
|
+
}.with_indifferent_access)
|
783
|
+
|
784
|
+
expect(param_keys[2].call).to eq('full_name')
|
785
|
+
expect(configuration[param_keys[2]]).to eq({
|
786
|
+
type: 'string',
|
787
|
+
nodoc: false,
|
788
|
+
ancestors: [param_keys[1]],
|
789
|
+
required: false,
|
790
|
+
}.with_indifferent_access)
|
791
|
+
end
|
792
|
+
end
|
793
|
+
|
794
|
+
context "when type is array" do
|
795
|
+
it "adds the field block to custom_response configuration" do
|
796
|
+
subject.brainstem_params do
|
797
|
+
actions :show do
|
798
|
+
response :hash do
|
799
|
+
fields :contacts, :array do
|
800
|
+
field :full_name, :string
|
801
|
+
end
|
802
|
+
end
|
803
|
+
end
|
804
|
+
end
|
805
|
+
|
806
|
+
configuration = subject.configuration[:show][:custom_response]
|
807
|
+
param_keys = configuration.keys
|
808
|
+
|
809
|
+
expect(param_keys[1].call).to eq('contacts')
|
810
|
+
expect(configuration[param_keys[1]]).to eq({
|
811
|
+
type: 'array',
|
812
|
+
item_type: 'hash',
|
813
|
+
nodoc: false,
|
814
|
+
required: false,
|
815
|
+
}.with_indifferent_access)
|
816
|
+
|
817
|
+
expect(param_keys[2].call).to eq('full_name')
|
818
|
+
expect(configuration[param_keys[2]]).to eq({
|
819
|
+
type: 'string',
|
820
|
+
nodoc: false,
|
821
|
+
required: false,
|
822
|
+
ancestors: [param_keys[1]]
|
823
|
+
}.with_indifferent_access)
|
824
|
+
end
|
825
|
+
end
|
826
|
+
|
827
|
+
context "when multi nested" do
|
828
|
+
it "adds the field block to custom_response configuration" do
|
829
|
+
subject.brainstem_params do
|
830
|
+
actions :show do
|
831
|
+
response :hash do
|
832
|
+
fields :contact, :hash, nodoc: true do
|
833
|
+
fields :details, :hash do
|
834
|
+
field :full_name, :string
|
835
|
+
end
|
836
|
+
end
|
837
|
+
end
|
838
|
+
end
|
839
|
+
end
|
840
|
+
|
841
|
+
configuration = subject.configuration[:show][:custom_response]
|
842
|
+
param_keys = configuration.keys
|
843
|
+
|
844
|
+
expect(param_keys[1].call).to eq('contact')
|
845
|
+
expect(configuration[param_keys[1]]).to eq({
|
846
|
+
type: 'hash',
|
847
|
+
nodoc: true,
|
848
|
+
required: false,
|
849
|
+
}.with_indifferent_access)
|
850
|
+
|
851
|
+
expect(param_keys[2].call).to eq('details')
|
852
|
+
expect(configuration[param_keys[2]]).to eq({
|
853
|
+
type: 'hash',
|
854
|
+
nodoc: true,
|
855
|
+
required: false,
|
856
|
+
ancestors: [param_keys[1]]
|
857
|
+
}.with_indifferent_access)
|
858
|
+
|
859
|
+
expect(param_keys[3].call).to eq('full_name')
|
860
|
+
expect(configuration[param_keys[3]]).to eq({
|
861
|
+
type: 'string',
|
862
|
+
nodoc: true,
|
863
|
+
required: false,
|
864
|
+
ancestors: [param_keys[1], param_keys[2]]
|
865
|
+
}.with_indifferent_access)
|
866
|
+
end
|
867
|
+
end
|
868
|
+
end
|
869
|
+
end
|
870
|
+
|
871
|
+
describe ".field" do
|
872
|
+
context "when used outside of the response block" do
|
873
|
+
it "raises an error" do
|
874
|
+
expect {
|
875
|
+
subject.brainstem_params do
|
876
|
+
actions :show do
|
877
|
+
field :full_name, :string
|
878
|
+
end
|
879
|
+
end
|
880
|
+
}.to raise_error(StandardError)
|
881
|
+
end
|
882
|
+
end
|
883
|
+
|
884
|
+
context "when used within the response block" do
|
885
|
+
context "when type is array" do
|
886
|
+
it "adds the field block to custom_response configuration" do
|
887
|
+
subject.brainstem_params do
|
888
|
+
actions :show do
|
889
|
+
response :hash do
|
890
|
+
field :names, :array
|
891
|
+
end
|
892
|
+
end
|
893
|
+
end
|
894
|
+
|
895
|
+
configuration = subject.configuration[:show][:custom_response]
|
896
|
+
param_keys = configuration.keys
|
897
|
+
|
898
|
+
expect(param_keys[1].call).to eq('names')
|
899
|
+
expect(configuration[param_keys[1]]).to eq({
|
900
|
+
type: 'array',
|
901
|
+
item_type: 'string',
|
902
|
+
nodoc: false,
|
903
|
+
required: false,
|
904
|
+
}.with_indifferent_access)
|
905
|
+
end
|
906
|
+
end
|
907
|
+
|
908
|
+
context "when type is not array" do
|
909
|
+
it "adds the field block to custom_response configuration" do
|
910
|
+
subject.brainstem_params do
|
911
|
+
actions :show do
|
912
|
+
response :hash do
|
913
|
+
field :full_name, :string
|
914
|
+
end
|
915
|
+
end
|
916
|
+
end
|
917
|
+
|
918
|
+
configuration = subject.configuration[:show][:custom_response]
|
919
|
+
param_keys = configuration.keys
|
920
|
+
|
921
|
+
expect(param_keys[1].call).to eq('full_name')
|
922
|
+
expect(configuration[param_keys[1]]).to eq({
|
923
|
+
type: 'string',
|
924
|
+
nodoc: false,
|
925
|
+
required: false,
|
926
|
+
}.with_indifferent_access)
|
927
|
+
end
|
928
|
+
end
|
929
|
+
|
930
|
+
context "when nested under parent field" do
|
931
|
+
it "inherits the nodoc attribute" do
|
932
|
+
subject.brainstem_params do
|
933
|
+
actions :show do
|
934
|
+
response :hash do
|
935
|
+
fields :contact, :hash, nodoc: true do
|
936
|
+
field :full_name, :string
|
937
|
+
end
|
938
|
+
end
|
939
|
+
end
|
940
|
+
end
|
941
|
+
|
942
|
+
configuration = subject.configuration[:show][:custom_response]
|
943
|
+
param_keys = configuration.keys
|
944
|
+
|
945
|
+
expect(param_keys[1].call).to eq('contact')
|
946
|
+
expect(configuration[param_keys[1]]).to eq({
|
947
|
+
type: 'hash',
|
948
|
+
nodoc: true,
|
949
|
+
required: false,
|
950
|
+
}.with_indifferent_access)
|
951
|
+
|
952
|
+
expect(param_keys[2].call).to eq('full_name')
|
953
|
+
expect(configuration[param_keys[2]]).to eq({
|
954
|
+
type: 'string',
|
955
|
+
nodoc: true,
|
956
|
+
required: false,
|
957
|
+
ancestors: [param_keys[1]]
|
958
|
+
}.with_indifferent_access)
|
959
|
+
end
|
960
|
+
end
|
961
|
+
end
|
962
|
+
end
|
963
|
+
|
964
|
+
describe ".operation_id" do
|
965
|
+
it "sets the operation_id for the context" do
|
966
|
+
subject.brainstem_params do
|
967
|
+
actions :show do
|
968
|
+
operation_id "getPetByID"
|
969
|
+
end
|
970
|
+
end
|
971
|
+
|
972
|
+
expect(subject.configuration[:show][:operation_id]).to eq("getPetByID")
|
973
|
+
end
|
974
|
+
|
975
|
+
context "when defined on the default context" do
|
976
|
+
it "raises an error" do
|
977
|
+
expect {
|
978
|
+
subject.brainstem_params do
|
979
|
+
operation_id :blah
|
980
|
+
end
|
981
|
+
}.to raise_error(StandardError)
|
982
|
+
end
|
983
|
+
end
|
984
|
+
end
|
985
|
+
|
986
|
+
describe ".consumes" do
|
987
|
+
it "sets the consumes property for the context" do
|
988
|
+
subject.brainstem_params do
|
989
|
+
consumes "application/xml", "application/json"
|
990
|
+
|
991
|
+
actions :show do
|
992
|
+
consumes ["application/x-www-form-urlencoded"]
|
993
|
+
end
|
994
|
+
end
|
995
|
+
|
996
|
+
expect(subject.configuration[:_default][:consumes]).to \
|
997
|
+
eq ["application/xml", "application/json"]
|
998
|
+
|
999
|
+
expect(subject.configuration[:show][:consumes]).to \
|
1000
|
+
eq ["application/x-www-form-urlencoded"]
|
1001
|
+
end
|
1002
|
+
end
|
1003
|
+
|
1004
|
+
describe ".produces" do
|
1005
|
+
it "sets the produces property for the context" do
|
1006
|
+
subject.brainstem_params do
|
1007
|
+
produces "application/xml"
|
1008
|
+
|
1009
|
+
actions :show do
|
1010
|
+
produces ["application/x-www-form-urlencoded"]
|
1011
|
+
end
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
expect(subject.configuration[:_default][:produces]).to \
|
1015
|
+
eq ["application/xml"]
|
1016
|
+
|
1017
|
+
expect(subject.configuration[:show][:produces]).to \
|
1018
|
+
eq ["application/x-www-form-urlencoded"]
|
1019
|
+
end
|
1020
|
+
end
|
1021
|
+
|
1022
|
+
describe ".security" do
|
1023
|
+
it "sets the security configuration for the context" do
|
1024
|
+
subject.brainstem_params do
|
1025
|
+
security []
|
1026
|
+
|
1027
|
+
actions :show do
|
1028
|
+
security({"petstore_auth" => [ "write:pets", "read:pets" ]})
|
1029
|
+
end
|
1030
|
+
end
|
1031
|
+
|
1032
|
+
expect(subject.configuration[:_default][:security]).to eq []
|
1033
|
+
expect(subject.configuration[:show][:security]).to eq([
|
1034
|
+
{ "petstore_auth" => [ "write:pets", "read:pets" ] }
|
1035
|
+
])
|
1036
|
+
end
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
describe ".external_doc" do
|
1040
|
+
it "sets the external_doc for the context" do
|
1041
|
+
subject.brainstem_params do
|
1042
|
+
actions :show do
|
1043
|
+
external_doc description: 'External Doc',
|
1044
|
+
url: 'www.blah.com'
|
1045
|
+
end
|
1046
|
+
end
|
1047
|
+
|
1048
|
+
expect(subject.configuration[:show][:external_doc]).to eq(
|
1049
|
+
'description' => 'External Doc',
|
1050
|
+
'url' => 'www.blah.com'
|
1051
|
+
)
|
1052
|
+
end
|
1053
|
+
end
|
1054
|
+
|
1055
|
+
describe ".schemes" do
|
1056
|
+
it "sets the schemes property for the context" do
|
1057
|
+
subject.brainstem_params do
|
1058
|
+
schemes "https"
|
1059
|
+
|
1060
|
+
actions :show do
|
1061
|
+
schemes ["http"]
|
1062
|
+
end
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
expect(subject.configuration[:_default][:schemes]).to eq ["https"]
|
1066
|
+
expect(subject.configuration[:show][:schemes]).to eq ["http"]
|
1067
|
+
end
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
describe ".deprecated" do
|
1071
|
+
it "sets the deprecated property for the context" do
|
1072
|
+
subject.brainstem_params do
|
1073
|
+
actions :show do
|
1074
|
+
deprecated true
|
1075
|
+
end
|
1076
|
+
end
|
1077
|
+
|
1078
|
+
expect(subject.configuration[:show][:deprecated]).to eq true
|
1079
|
+
end
|
1080
|
+
end
|
1081
|
+
|
716
1082
|
describe "#valid_params_tree" do
|
717
1083
|
context "when no root is specified" do
|
718
1084
|
it "returns the field names as the top level keys" do
|