diff --git a/examples/core_api/argument_sets/single_lookup.rb b/examples/core_api/argument_sets/single_lookup.rb new file mode 100644 index 0000000..85b27eb --- /dev/null +++ b/examples/core_api/argument_sets/single_lookup.rb @@ -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 diff --git a/examples/core_api/endpoints/test_endpoint.rb b/examples/core_api/endpoints/test_endpoint.rb index 8f49b72..7a99d21 100644 --- a/examples/core_api/endpoints/test_endpoint.rb +++ b/examples/core_api/endpoints/test_endpoint.rb @@ -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 @@ -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 diff --git a/lib/apia/open_api/objects/parameters.rb b/lib/apia/open_api/objects/parameters.rb index 7951222..1bc14c5 100644 --- a/lib/apia/open_api/objects/parameters.rb +++ b/lib/apia/open_api/objects/parameters.rb @@ -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, diff --git a/lib/apia/open_api/objects/schema.rb b/lib/apia/open_api/objects/schema.rb index f42f0d4..227cd4c 100644 --- a/lib/apia/open_api/objects/schema.rb +++ b/lib/apia/open_api/objects/schema.rb @@ -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 diff --git a/spec/support/fixtures/openapi.json b/spec/support/fixtures/openapi.json index 29c361c..0d258d4 100644 --- a/spec/support/fixtures/openapi.json +++ b/spec/support/fixtures/openapi.json @@ -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", @@ -916,6 +924,9 @@ "object": { "$ref": "#/components/schemas/ObjectLookup" }, + "thing": { + "$ref": "#/components/schemas/SingleLookup" + }, "scalar": { "type": "string", "description": "Any string will do, it's not validated" @@ -923,6 +934,7 @@ }, "required": [ "object", + "thing", "scalar" ] } @@ -1483,6 +1495,14 @@ "object_not_found" ] }, + "SingleLookup": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + } + }, "PostTestObject200ResponseTime": { "type": "object", "properties": {