Skip to content

Syntax error when enum in a Schema Object is a list of objects #876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
denniskloyn opened this issue Feb 7, 2022 · 6 comments
Closed

Syntax error when enum in a Schema Object is a list of objects #876

denniskloyn opened this issue Feb 7, 2022 · 6 comments
Labels
bug Something isn't working planned Expected in an upcoming version PRs welcome PRs are welcome to solve this issue!

Comments

@denniskloyn
Copy link

If a Schema Object enum contains a list of objects (instead of—more commonly—a list strings) an error is thrown: SyntaxError: '=>' expected. This error message looks similar to the one in bug #561.

Note that an enum in a schema object may contain a list of anything. As per https://swagger.io/specification/#schema-object enum “[is] taken directly from the JSON Schema definition and follow[s] the same specifications”. The JSON Schema definition, https://datatracker.ietf.org/doc/html/draft-wright-json-schema-validation-00#section-5.20, says that “Elements in the array MAY be of any type, including null.”

@rkulinski
Copy link

rkulinski commented Feb 11, 2022

I think I'm experiencing the same issue but with different error:

(node:59042) UnhandledPromiseRejectionWarning: SyntaxError: ',' expected. (2448:22)

 /** @enum {array} */
> 2448 | "_entity": [object Object];

It seems like this library has a bug when reading enum

@drwpow drwpow added bug Something isn't working PRs welcome PRs are welcome to solve this issue! labels Feb 13, 2022
@Leafgard
Copy link

Leafgard commented Feb 26, 2022

Experiencing the same issue while parsing Docker v1.41 OpenApi specs:

SyntaxError: ',' expected. (1404:43)
  1402 |   * `{"<port>/<tcp|udp|sctp>": {}}`
  1403 |   */
> 1404 | "ExposedPorts"?: { [key: string]: [object Object]; };

So far it seems like @rkulinski is right, this is most likely due to enums, but more specifically: empty enums. There are multiple enums before the one which crashes on Docker OpenApi specs, and the only ones crashing on my side are the empty ones, f.e:

ExposedPorts:
  description: |
    An object mapping ports to an empty object in the form:

    `{"<port>/<tcp|udp|sctp>": {}}`
  type: "object"
  additionalProperties:
    type: "object"
    enum:
      - {}
    default: {}

Could you please confirm on your side that this may be the issue for you as well @rkulinski ? 😄

@michael-land
Copy link

michael-land commented Mar 2, 2022

experencing the same issue when parsing mailchimp openapi spec,

https://api.mailchimp.com/schema/3.0/Swagger.json?expand

  {
            "in": "query",
            "name": "activity_filters",
            "x-title": "Activity Filters",
            "type": "array",
            "required": false,
            "items": {
              "type": "string"
            },
            "collectionFormat": "csv",
            // error happened here
            "enum": [
              [
                "bounce"
              ],
			 // other options removed
            ],
            "description": "A comma-separated list of activity filters that correspond to a set of activity types, e.g \"?activity_filters=open,bounce,click\"."
          }

The generated enum value miss quotes.

image

@Gankarloo
Copy link

I'm facing the exact same issue as @Leafgard

@drwpow
Copy link
Contributor

drwpow commented Mar 28, 2022

This definitely seems like a bug. If someone is able to create a PR to fix this (with tests) I’d be happy to merge & release

@drwpow drwpow added the planned Expected in an upcoming version label Nov 4, 2022
@drwpow
Copy link
Contributor

drwpow commented Nov 4, 2022

This has been added in the upcoming v6 version (#968). Closing in anticipation of that, but once that’s launched, if there are any issues please file additional bugs.

@drwpow drwpow closed this as completed Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working planned Expected in an upcoming version PRs welcome PRs are welcome to solve this issue!
Projects
None yet
Development

No branches or pull requests

6 participants