Skip to content

Enum are "anonymous" in the Model preview section, it shows only "Enum" - 3.x #2875

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
matthieugeerebaert opened this issue Apr 7, 2017 · 6 comments

Comments

@matthieugeerebaert
Copy link

matthieugeerebaert commented Apr 7, 2017

There are two points:
enum reference from parameter, and enum reference from another definition object

This definition was ok for swagger-ui 2.x and swagger-parser": "~3.4.1. But it is now ko with swagger-ui 3.x and online swagger editor.. :(

In swagger-ui 3.x both model and parameter are "anonymous"

  "definitions": {
    "Type": {
      "description": "",
      "type": "string",
      "enum": [
        "1",
        "2",
        "3",
        "4"
      ]
    }
  }

enum.swagger.json.zip

enum

image

In swagger editor: error for parameter reference

image

It's very confusing from one version to another, and from one tool to another :)

@webron
Copy link
Contributor

webron commented Apr 7, 2017

As you said, there are two separate issues here.

In the models view (@bodnia) - anything that's not an object has no name, an it should (the name of the definition).

In the operation view - you can't reference types from non-body parameters. This is split into two - @shockey, we need to make sure the new validator marks this as an error (like the old one). And two (@bodnia, @shockey) - no type should be displayed for the parameter when it's invalid.

@matthieugeerebaert
Copy link
Author

Hello,

Concerning "you can't reference types from non-body parameters", I think the problem is more relative to Open API Initiative spec. Problem for current spec with enums, wich are absolutely usable as query or path param ( string, int etc ), is that when using code generator we are facing anonymous enums, sometimes 3/4 times the same enum.. That's why we used to referenced enum definition from non body parameters. It worked like a charm before with swagger-ui ui 2., and swagger code gen :)

OAI ( swagger ) should allow use of enum definition :) It 's also more natural to define them in model and then use it in model, body param, or path/query/header param

@webron
Copy link
Contributor

webron commented Apr 10, 2017

3.0 is already going to allow it. But 2.0 does not, and we will not support it in the UI. You can still use enums directly in the parameter definition, just not reference it.

@hkosova
Copy link
Contributor

hkosova commented Apr 10, 2017

There's a workaround to reference an enum using YAML &anchors as shown in OAI/OpenAPI-Specification#300 (comment). Not all tools support that - it depends on the tool's YAML parser - but Swagger UI does.

@webron
Copy link
Contributor

webron commented Jun 5, 2018

Non-object definitions now have the name displayed under the Models section, and the editor shows errors for the wrong definition.

@webron webron closed this as completed Jun 5, 2018
@lock
Copy link

lock bot commented Jul 1, 2019

Locking due to inactivity.
This is done to avoid resurrecting old issues and bumping long threads with new, possibly unrelated content.
If you think you're experiencing something similar to what you've found here: please open a new issue, follow the template, and reference this issue in your report.
Thanks!

@lock lock bot unassigned bodnia Jul 1, 2019
@lock lock bot locked and limited conversation to collaborators Jul 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants