Skip to content
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,9 @@ Apipie::prop(<property-name>, <property-type>, <options-hash> [, <array of sub-p
# options-hash can include any of the options fields allowed in a :returns statement.
# additionally, it can include the ':is_array => true', in which case the property is understood to be
# an array of the described type.
#
# x-extensions: any option key starting with 'x-' will be passed through to the
# generated OpenAPI/Swagger specification. This is useful for vendor-specific extensions.
```

To describe an embedded object:
Expand Down
5 changes: 5 additions & 0 deletions lib/apipie/generator/swagger/param_description/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def to_swagger
definition.merge!(for_required)
definition.merge!(for_example)
definition.merge!(@description.to_hash) if @description.present?
definition.merge!(for_x_extensions)

warn_optional_without_default_value(definition)

Expand All @@ -63,6 +64,10 @@ def to_swagger

private

def for_x_extensions
@param_description.options.select { |key, _| key.to_s.start_with?('x-') }
end

def for_required
return {} if !required?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,33 @@
it { is_expected.to eq('example') }
end
end

describe 'x-extensions' do
context 'when x-extension options are provided' do
let(:base_param_description_options) do
{
required: true,
'x-param-sensitive': true,
'x-custom-extension': 'custom-value'
}
end

it 'includes x-param-sensitive in the output' do
expect(generated_block[:'x-param-sensitive']).to eq(true)
end

it 'includes x-custom-extension in the output' do
expect(generated_block[:'x-custom-extension']).to eq('custom-value')
end
end

context 'when no x-extension options are provided' do
let(:base_param_description_options) { { required: true } }

it 'does not include any x-extension keys' do
x_extension_keys = generated_block.keys.select { |k| k.to_s.start_with?('x-') }
expect(x_extension_keys).to be_empty
end
end
end
end