Length limits (minLength/maxLength, minItems/maxItems) are dropped from body params moved into a definition
I maintainer di solito rispondono entro 1 giorno
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_keyscopies a fixed list of keys, which doesn't includeminLength/maxLength.MoveParams.document_as_arraybuilds the array property by hand (type,description,example,items), sominItems/maxItemsare 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
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ruby-grape/grape-swagger
-
Support default_response and default in 2.3; stop reading route.descForse già presa @numbata l’ha presa 53 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ruby-grape/grape-swagger#989 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
ruby-grape/grape-swagger#987 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Bug report: omitted array parameters with `array_use_braces: true`Forse già presa @olivier-thatch l’ha presa 527 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
ruby-grape/grape-swagger#952 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Report: `default` for array params (`type: [String]`) is incorrectly placed inside `items`Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
ruby-grape/grape-swagger#950 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Setting add_base_path without base_path explicitly specified, returned an errorForse già presa @bekicot l’ha presa 837 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
ruby-grape/grape-swagger#935 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ruby-grape/grape-swagger
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
shakacode/react_on_rails#5295 ·
I maintainer di solito rispondono entro 1 giorno
-
account: profile bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
metanorma/metanorma-standoc#1315 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
metanorma/metanorma-iso#1681 ·
I maintainer di solito rispondono entro 1 giorno