Skip to content
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

Enums of any value type (specifically booleans) should be accepted #112

Open
aSapien opened this issue Jul 14, 2019 · 2 comments
Open

Enums of any value type (specifically booleans) should be accepted #112

aSapien opened this issue Jul 14, 2019 · 2 comments

Comments

@aSapien
Copy link

aSapien commented Jul 14, 2019

Reproduction steps:

  1. Download Slack's Swagger API json here:
    curl -O https://api.slack.com/specs/openapi/v2/slack_web.json
  2. Attempt to generate:
    openapi2proto -spec ./slack_web.json
  3. Result:
    error: failed to transpile: failed to load OpenAPI spec: failed to decode content: failed to unmarshal JSON: json: cannot unmarshal bool into Go struct field .enum of type string

Unfortunately I have little to no experience with Golang, so I'm pretty much clueless :/

Appreciate any help here

@jprobinson
Copy link
Contributor

The root of the error message is the key here:

cannot unmarshal bool into Go struct field .enum of type string

This points to a field named "enum" that has a boolean value instead of an expected string. It appears that the kind folks of Slack decided they needed to declare additional enum values/constants that reattempt to define their own custom "true" and "false" constants as booleans.

        "defs_ok_false": {
            "enum": [
                false
            ],
            "title": "default failure response",
            "type": "boolean"
        },
        "defs_ok_true": {
            "enum": [
                true
            ],
            "title": "default success response",
            "type": "boolean"
        },

This is kinda nutty IMO but it appears to match the OpenAPI 2.0 spec that an enum can be of "any" type.

Right now, openapi2proto expects enums to have strings as values, which is causing the error. I hope you don't mind, but I'll rename this issue to better describe the problem at hand.

@jprobinson jprobinson changed the title Unable to unmarshall Slack's Swagger 2 API Enums of any value type (specifically booleans) should be accepted Jul 14, 2019
@aSapien
Copy link
Author

aSapien commented Jul 14, 2019

Thanks @jprobinson! Indeed it looks like their API is a mess. I've been trying to generate Slack's entities for quite some time. Unfortunately, openapi-generator also fails to generate data classes

I really hope somebody there is listening and the issue will be addressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants