Skip to content

Commit

Permalink
fix: only add mutually exclusive description if there are multiple ar…
Browse files Browse the repository at this point in the history
…guments in a lookup argument set
  • Loading branch information
ikadix committed Oct 15, 2024
1 parent 543dba2 commit ad135cb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
14 changes: 14 additions & 0 deletions examples/core_api/argument_sets/single_lookup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module CoreAPI
module ArgumentSets
class SingleLookup < Apia::LookupArgumentSet

name "Single Lookup"
description "Provides for something to be looked up"

argument :id, type: :string

end
end
end
2 changes: 2 additions & 0 deletions examples/core_api/endpoints/test_endpoint.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "core_api/argument_sets/object_lookup"
require "core_api/argument_sets/single_lookup"

module CoreAPI
module Endpoints
Expand All @@ -10,6 +11,7 @@ class TestEndpoint < Apia::Endpoint
description "Returns the current time"

argument :object, type: ArgumentSets::ObjectLookup, required: true
argument :thing, type: ArgumentSets::SingleLookup, required: true
argument :scalar, type: :string, required: true do
description "Any string will do, it's not validated"
end
Expand Down
3 changes: 2 additions & 1 deletion lib/apia/open_api/objects/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def add_description_section(description, addition)
end

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

add_description_section(
description,
Expand Down
4 changes: 3 additions & 1 deletion lib/apia/open_api/objects/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def generate_child_schemas
@children = @definition.fields.values
elsif @definition.type.argument_set?
@children = @definition.type.klass.definition.arguments.values
if @definition.type.klass.ancestors.include?(Apia::LookupArgumentSet)
if @definition.type.klass.ancestors.include?(Apia::LookupArgumentSet) &&
@definition.type.klass.definition.arguments.length > 1

@schema[:description] ||=
"All '#{@definition.name}[]' params are mutually exclusive, only one can be provided."
end
Expand Down
20 changes: 20 additions & 0 deletions spec/support/fixtures/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,14 @@
},
"description": "The permalink of the object to look up. \n\n All 'object[]' params are mutually exclusive, only one can be provided."
},
{
"in": "query",
"name": "thing[id]",
"schema": {
"type": "string"
},
"description": ""
},
{
"name": "scalar",
"in": "query",
Expand Down Expand Up @@ -916,13 +924,17 @@
"object": {
"$ref": "#/components/schemas/ObjectLookup"
},
"thing": {
"$ref": "#/components/schemas/SingleLookup"
},
"scalar": {
"type": "string",
"description": "Any string will do, it's not validated"
}
},
"required": [
"object",
"thing",
"scalar"
]
}
Expand Down Expand Up @@ -1483,6 +1495,14 @@
"object_not_found"
]
},
"SingleLookup": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
},
"PostTestObject200ResponseTime": {
"type": "object",
"properties": {
Expand Down

0 comments on commit ad135cb

Please sign in to comment.