Bug Report: `default` for array params (`type: [String]`) is incorrectly placed inside `items`
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- openapi, ruby
- Área
- api, documentation
Línea de trabajo
Start by reproducing the array parameter declaration from the issue and inspect the schema-generation path that places defaults on array items. Compare the generated OpenAPI output with the expected array-level default, then verify the corrected schema against the Swagger Editor example and related behavior in PR #651.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
When using the following parameter declaration in Grape:
optional :dns_servers, type: [String], desc: 'DNS servers', allow_blank: false, default: ["8.8.8.8", "8.8.4.4"]
grape-swagger generates an OpenAPI schema where the default value is incorrectly placed inside items, instead of being set at the array level. This causes the field to be interpreted as a nested array ([[value]]) in Swagger tools and breaks the expected structure.
🔍 Current Behavior (Incorrect)
Generated OpenAPI snippet:
dns_servers:
type: array
items:
type: string
default: ["8.8.8.8", "8.8.4.4"] # ❌ incorrect placement — default on items must be a single value, not an array
⚠️ Swagger Editor interprets this as:
"dns_servers": [
["8.8.8.8", "8.8.4.4"]
]
Which is not the intended behavior, and breaks compatibility with clients, documentation, and tools.
✅ Expected Behavior
The correct OpenAPI output should look like this:
dns_servers:
type: array
items:
type: string
default:
- "8.8.8.8"
- "8.8.4.4"
This correctly documents a default array of strings, not a nested array of arrays.
🧪 Minimal Reproducible Example (Swagger Editor — OpenAPI 2.0 - https://editor.swagger.io)
swagger: "2.0"
info:
title: DNS Servers Example
version: "1.0"
paths:
/example:
post:
parameters:
- in: body
name: postV1Organization
required: true
schema:
type: object
properties:
dns_servers:
type: array
items:
type: string
default: ["8.8.8.8", "8.8.4.4"] # ❌ incorrect — invalid type, causes nested array
responses:
200:
description: OK
✅ Correct version for comparison:
dns_servers:
type: array
items:
type: string
default:
- "8.8.8.8"
- "8.8.4.4"
📚 Specification Insights (OpenAPI & JSON Schema)
-
The
defaultvalue represents what would be assumed by the consumer of the input if one is not provided. It MUST conform to the defined type for the schema object. -
The value MUST conform to the defined type for the data type.
-
The instance MUST be equal to one of the values in the array.
-
It is RECOMMENDED that a default value be valid against the associated schema.
🔎 Why this matters
- Placing
defaultinsideitemsimplies a per-item default, which is not meaningful for array parameters. - Putting an array value as the
defaultinsideitems(which expects a scalar) leads to nested arrays and invalid schemas. - This issue causes confusion in docs, misbehavior in tools, and breaks conformity with OpenAPI semantics.
🔗 Related
- Related incorrect behavior: Pull Request #651
- Prior issue (broader context): Issue #650
📦 Version Info
ruby:3.3.4grape:2.3.0grape-swagger:2.1.2
💡 Suggestion: when generating schemas from type: [String] with a default, grape-swagger should ensure the default is set at the array level — not inside items, and that its type conforms to OpenAPI expectations.
- Lenguaje dominante
- Ruby
- Estrellas
- 1.1k
- Forks
- 478
- Merge medio
- 7 h 25 min
- PR fusionados (30 d)
- 1
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ruby-grape/grape-swagger
-
Support default_response and default in 2.3; stop reading route.descPosiblemente ocupada @numbata la tomó hace 47 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ruby-grape/grape-swagger#989 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
ruby-grape/grape-swagger#987 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Bug report: omitted array parameters with `array_use_braces: true`Posiblemente ocupada @olivier-thatch la tomó hace 521 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
ruby-grape/grape-swagger#952 · 2 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Setting add_base_path without base_path explicitly specified, returned an errorPosiblemente ocupada @bekicot la tomó hace 830 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
ruby-grape/grape-swagger#935 ·
Los mantenedores suelen responder en 1 día
-
Wrong route orderingAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
ruby-grape/grape-swagger#921 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de ruby-grape/grape-swagger
Issues similares
-
[Bug] Chatwoot v4.19.0 – Super Admin returns 500 due to missing superadmin.scss Vite manifest entryAbiertoBug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 2 días
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
-
Ruby 4.0.9, 3.4.12, 3.3.13Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
internal
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Kong/developer.konghq.com#7716 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100