prism icon indicating copy to clipboard operation
prism copied to clipboard

Enum example is not picked up as mock response

Open Ronaldvdh-ISAAC opened this issue 3 years ago • 1 comments

Describe the bug

When defining an example value for an enum, the mock server will still return the first item in the ENUM as response.

To Reproduce

  1. Given this OpenAPI document
openapi: 3.0.3

tags:
  - name: Example
    description: Example

info:
  title: Example enum response
  contact:
    name: Example
  description: >-
    Example
  version: '1'

servers:
  - url: http://localhost
    description: localhost

paths:
  '/enum':
    get:
      tags:
        - Example
      description: >-
        get Enum
      operationId: getEnum
      responses:
        '200':
          description: enum
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum:
                      - FAILURE
                      - SUCCESS
                    example: SUCCESS
  1. Run this CLI command
prism mock openApi.yaml
  1. See result The endpoint /enum returns status: FAILURE

Expected behavior

As the example: SUCCESS is added to the document i expect this value of the enum to be returned.

Additional context

editor.swagger.io does pick up the specified example value instead of the first value of the enum

Environment (remove any that are not applicable):

  • Library version: 4.5.0

Ronaldvdh-ISAAC avatar Dec 13 '21 14:12 Ronaldvdh-ISAAC

For now, we recommend the work-around of re-ordering enums to place the desired static mock response first, but we've got this on our radar!

EdVinyard avatar May 06 '22 16:05 EdVinyard