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

Example value shows datatype inplace of actual value #3960

Closed
gohelkiran30 opened this issue Nov 29, 2017 · 4 comments
Closed

Example value shows datatype inplace of actual value #3960

gohelkiran30 opened this issue Nov 29, 2017 · 4 comments

Comments

@gohelkiran30
Copy link

after update to version 3.4.4 the example value of an object is replaced with its data type, when uses definitions

Earlier response is like (in v2.2.6)

  "vehicleType": {
    "id": 1,
    "en": "Car"
  },

now it is changed to (in v3.4.4)

 "vehicleType": {
    "id": 0,
    "en": "string"
  },
Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version?
Which Swagger-UI version? 3.4.4
How did you install Swagger-UI? using dist directory
Which browser & version? all browser
Which operating system? checked in windows/linux/ubuntu

Demonstration API definition

      vehicleType:
        description: vehicle type
        type: object
        $ref: '#/definitions/Option'
        example:
          id: 1
          en: Car

  Option:
    type: object
    title: Option
    required:
      - id
      - en
    properties:
      id:
        type: integer
        description: Id of the option
      en:
        type: string
        description: English name for option value
      aliases:
        type: array
        description: List of alias name for option value
        items:
          type: string

your: "API definition goes here"

Configuration (browser query string, constructor, config.yaml)

{
  "your": { "constructorConfig": "here" }
}

?yourQueryStringConfig=here

Expected Behavior

"vehicleType": {
"id": 1,
"en": "Car"
},

Current Behavior

"vehicleType": {
"id": 0,
"en": "string",
"aliases": [
"string"
]
},

Possible Solution

Context

api user cannot the example values

@hkosova
Copy link
Contributor

hkosova commented Nov 29, 2017

vehicleType:
  description: vehicle type
  type: object
  $ref: '#/definitions/Option'
  example:
    id: 1
    en: Car

$ref works by replacing all of its sibling elements with the definition the $ref is pointing at. So the example in the schema above is not actually used, it's overwritten by $ref.

Specify the example values in the Option schema instead.

@gohelkiran30
Copy link
Author

@hkosova definition is used more than 1 place and most places have different example values. So adding example values in schema is not that useful. For example take an option schema for an entities, the format is same but the values will be different for each entity.

@hkosova
Copy link
Contributor

hkosova commented Nov 29, 2017

@gohelkiran30 You can try this ugly hack, it seems to work in the latest UI and Editor but I don't know if this will work in other tools (codegen, etc.)

vehicleType:
  allOf:
    - $ref: '#/definitions/Option'
  description: vehicle type
  example:
    id: 1
    en: Car

Or if you use OpenAPI 3.0, it lets you define separate examples for request bodies and response bodies. But these examples are not currently displayed in UI (#3437).

@shockey
Copy link
Contributor

shockey commented Dec 8, 2017

Closing due to inactivity.

This is simply to keep our issue tracker clean - feel free to comment if there are any further thoughts or concerns, and we'll be happy to reopen this issue.

@shockey shockey closed this as completed Dec 8, 2017
@lock lock bot locked and limited conversation to collaborators Jul 2, 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

3 participants