JSON params are documented with the invalid type "json"

Open Beginner friendly
#1,014 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
json, ruby
Domain
documentation

Research direction

The bad type comes from GrapeSwagger::DocMethods::DataType.call, where JSON is lowercased alongside the primitive types, and from the request_primitives list that includes json. Read both to see how a JSON param reaches the spec as type json. Done when requires :a, type: JSON and Array[JSON] emit type object in both query and body definitions, with or without array_use_braces.

Written by the indexing model from the issue text.

Description

requires :a, type: Array[JSON] produces:

"a": { "type": "array", "items": { "type": "json" } }

A scalar requires :a, type: JSON does the same ("type": "json" in both query parameters and body definitions). json is not a valid Swagger 2.0 type, so the generated spec fails validation. The output is the same with or without array_use_braces.

Expected: a valid schema. The usual choice is type: object, as Hash already maps to object.

Probably in GrapeSwagger::DocMethods::DataType.call, where JSON is lowercased together with the primitive types, and request_primitives, which lists json.

Dominant language
Ruby
Stars
1.1k
Forks
477
Avg merge
1d 18h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby-grape/grape-swagger

All issues in ruby-grape/grape-swagger

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.