swagger-api / swagger-api/swagger-parser

Consider translate enum types to encompassing types

Open
#283 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

In some cases, users will use the wrong data type for enum values. Considering the following two cases:

type: string
enum:
  - true
  - false
type: integer
enum:
  - "2"
  - "3"

In the first example the type is string but the values are boolean (values need to be explicitly quoted in this case). In the second example the type is integer but the values are actually strings.

When it comes to JSON Schema validation, nothing will validate against such a definition because both are required to be validated, but it may be safe to assume that the intent of the author was to use the explicit data type as specified by the type. To resolve it, the parser can apply the type to the values of the enum and avoid potential issues.

Pro:

  • Makes the parser (and using tools) more friendly to user errors.

Con:

  • May ignore a potentially critical user error.

Consideration:

  • Not all cases could be converted, for example:
type: integer
enum:
  - 2.1
  - 2.2

Contributor guide

Open the contributing guide

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.

Research direction

No files or tests are named in the issue. Start by locating the parser's handling of schema type and enum values, then determine how conversion should behave for the string/boolean and integer/string examples, including the non-convertible numeric case. Done means the chosen behavior is implemented and covered by tests without silently mishandling invalid definitions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.