Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Length limits (minLength/maxLength, minItems/maxItems) are dropped from body params moved into a definition

Aperta
#1,010 1 commento 1 reazione 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@numbata ci sta già lavorando.

Dal 26/10/2026.

  • #1011 di @numbata — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

Versions

grape-swagger 2.1.4 (the same code is on master).

What happens

https://github.com/ruby-grape/grape-swagger/pull/934 documents length: limits. That works for query and path params. For body params on POST/PUT/PATCH, DocMethods::MoveParams moves the params into a definition, and the limits are lost on the way:

  • MoveParams.property_keys copies a fixed list of keys, which doesn't include minLength / maxLength.
  • MoveParams.document_as_array builds the array property by hand (type, description, example, items), so minItems / maxItems are dropped.
Repro
require 'grape'
require 'grape-swagger'
require 'json'

class API < Grape::API
  format :json

  params do
    requires :name, type: String, length: { max: 50 }
    requires :tags, type: Array[String], length: { max: 3 }
  end
  post :things do; end

  add_swagger_documentation
end

env = Rack::MockRequest.env_for('/swagger_doc')
_status, _headers, body = API.call(env)
puts JSON.pretty_generate(JSON.parse(body.each.to_a.join)['definitions'])
Expected
"name": { "type": "string", "maxLength": 50 },
"tags": { "type": "array", "items": { "type": "string" }, "maxItems": 3 }
Actual
"name": { "type": "string" },
"tags": { "type": "array", "items": { "type": "string" } }
Possible workaround / fix

Prepending this makes the repro print the expected output:

module KeepLengthLimits
  private

  def property_keys
    super | %i[minLength maxLength]
  end

  def document_as_array(param)
    super.merge(param.slice(:minItems, :maxItems))
  end
end

GrapeSwagger::DocMethods::MoveParams.singleton_class.prepend(KeepLengthLimits)

A fix in the gem would probably be adding minLength / maxLength to property_keys and copying minItems / maxItems in document_as_array.

Lingua principale
Ruby
Stelle
1.1k
Fork
477
Merge medio
5h 25m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby-grape/grape-swagger

Tutte le issue di ruby-grape/grape-swagger

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.