Skip to content

Commit 7b5d5e7

Browse files
authored
fix: only add mutually exclusive description if there are multiple arguments in a lookup argument set (#83)
1 parent 543dba2 commit 7b5d5e7

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
module CoreAPI
4+
module ArgumentSets
5+
class SingleLookup < Apia::LookupArgumentSet
6+
7+
name "Single Lookup"
8+
description "Provides for something to be looked up"
9+
10+
argument :id, type: :string
11+
12+
end
13+
end
14+
end

examples/core_api/endpoints/test_endpoint.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "core_api/argument_sets/object_lookup"
4+
require "core_api/argument_sets/single_lookup"
45

56
module CoreAPI
67
module Endpoints
@@ -10,6 +11,7 @@ class TestEndpoint < Apia::Endpoint
1011
description "Returns the current time"
1112

1213
argument :object, type: ArgumentSets::ObjectLookup, required: true
14+
argument :thing, type: ArgumentSets::SingleLookup, required: true
1315
argument :scalar, type: :string, required: true do
1416
description "Any string will do, it's not validated"
1517
end

lib/apia/open_api/objects/parameters.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ def add_description_section(description, addition)
146146
end
147147

148148
def add_lookup_description(description)
149-
return unless @argument.type.klass.ancestors.include?(Apia::LookupArgumentSet)
149+
return unless @argument.type.klass.ancestors.include?(Apia::LookupArgumentSet) &&
150+
@argument.type.klass.definition.arguments.length > 1
150151

151152
add_description_section(
152153
description,

lib/apia/open_api/objects/schema.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ def generate_child_schemas
8080
@children = @definition.fields.values
8181
elsif @definition.type.argument_set?
8282
@children = @definition.type.klass.definition.arguments.values
83-
if @definition.type.klass.ancestors.include?(Apia::LookupArgumentSet)
83+
if @definition.type.klass.ancestors.include?(Apia::LookupArgumentSet) &&
84+
@definition.type.klass.definition.arguments.length > 1
85+
8486
@schema[:description] ||=
8587
"All '#{@definition.name}[]' params are mutually exclusive, only one can be provided."
8688
end

spec/support/fixtures/openapi.json

+20
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,14 @@
841841
},
842842
"description": "The permalink of the object to look up. \n\n All 'object[]' params are mutually exclusive, only one can be provided."
843843
},
844+
{
845+
"in": "query",
846+
"name": "thing[id]",
847+
"schema": {
848+
"type": "string"
849+
},
850+
"description": ""
851+
},
844852
{
845853
"name": "scalar",
846854
"in": "query",
@@ -916,13 +924,17 @@
916924
"object": {
917925
"$ref": "#/components/schemas/ObjectLookup"
918926
},
927+
"thing": {
928+
"$ref": "#/components/schemas/SingleLookup"
929+
},
919930
"scalar": {
920931
"type": "string",
921932
"description": "Any string will do, it's not validated"
922933
}
923934
},
924935
"required": [
925936
"object",
937+
"thing",
926938
"scalar"
927939
]
928940
}
@@ -1483,6 +1495,14 @@
14831495
"object_not_found"
14841496
]
14851497
},
1498+
"SingleLookup": {
1499+
"type": "object",
1500+
"properties": {
1501+
"id": {
1502+
"type": "string"
1503+
}
1504+
}
1505+
},
14861506
"PostTestObject200ResponseTime": {
14871507
"type": "object",
14881508
"properties": {

0 commit comments

Comments
 (0)