Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only add mutually exclusive description if there are multiple arguments in a lookup argument set #83

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading