Swagger (springfox) don't show an example from an openapi yaml file

Viewed 105

I'm using

  1. org.springframework.boot:spring-boot-starter-web:2.2.6-Release
  2. swagger: io.springfox:springfox-boot-starter:3.0.0
  3. plugin org.openapi.generator:6.0.1

I made a yaml file with OpenAPI description of my end-points.

openapi: 3.0.3
info:
  title: a
  description: a
  contact:
    name: a
    url: ''
    email: a@gmai.com
  version: 'Latest'
tags:
  - name: V1Api
    description: a
paths:
  '/v1/getSome':
    get:
      tags:
        - V1Api
      summary: summary
      operationId: getSome
      deprecated: false
      responses:
        '200':
          description: 'OK'
          content:
            application/json:
              schema:
                type: object
                description: a
                properties:
                  field_1:
                    description: field_1 description
                    type: boolean
                    example: true
                  field_2:
                    description: field_2 description
                    type: string
                    example: 'field_2 example'
              example:
                  field_1: false
                  field_2: 'field_2 overriden example'

Without the example section. Only with examples for particular fields Pic1. Without the example section. Only with examples for particular fields

With the example section. It overrides the fields examples Pic2. With the example section. It overrides the fields examples

I tried my yaml file in https://editor.swagger.io/ and got the desired swagger state. Swagger showed the example section ({field_1: false, field_2: 'field_2 overriden example'}) correctly. When I used the yaml in my project Swagger didn't show the example above. I check the code generated from the yaml. It didn't have that example. I decided to check what code would be generated by https://editor.swagger.io/ if I choose "Generate Server -> spring". I didn't find the example there.

  1. Why does the spring code generator ignore that example?
  2. What should I do to make Swagger show that example?
0 Answers
Related