cancel
Showing results for 
Search instead for 
Did you mean: 

Swagger codegen/Swagger editor don't want to generate example

SOLVED
Visitor

Swagger codegen/Swagger editor don't want to generate example

Hello,

 

I'm learning Swagger and I had a problem while building my application.

Indeed, the auto-generate code don't want to generate my examples (I generated only Spring server).

 

Here is the yaml file (I copy/paste the doc to be sure I wasn't wrong) :

 

swagger: "2.0"
info:
  description: "This is the test's API from the web simulation."
  version: "1.0.0"
  title: "Plateform"
  termsOfService: "http://swagger.io/terms/"
  contact:
    email: "test@test.com"
  license:
    name: "Apache 2.0"
    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "localhost:8080"
basePath: "/"
tags:
- name: "test"
  description: "Everything"
schemes:
- "https"
- "http"

paths:
  /test:
    get:
      tags:
      - "test"
      summary: "Get"
      description: ""
      operationId: "get"
      produces:
      - "application/json"
      responses:
        200:
          description: OK
          examples:
            application/json: { "id": 38, "title": "T-shirt" }
            text/csv: >
              id,title
              38,T-shirt

 

 

In the editor, I got the right example :

EditorEditor

 

But when I try to generate the code I got this :Editor autogen.PNG

 

I got the same problem when I try to add any example (in /#/definitions/ for example).

 

I generate the code with Swagger codegen 2.0 and 3.0, and with the tool integrated in the Swagger Editor, but it return the same thing.

 

I'm on Ubuntu and using Maven to run the Spring-boot server.

 

Do you see anything I did wrong ?

 

 

Thanks in advance for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Staff

Re: Swagger codegen/Swagger editor don't want to generate example

 I am not sure I fully understand the issue, however if I get this correctly you are generating a spring server stub using the "spring" generator; and your second screenshot is the swagger-ui embedded into the result code. Each generator behaves differently and has different capabilities, in this case the generated server code is using springfox project to expose a Swagger definition resolved from the Api/Controller code. The generated code doesn't add for example annotations to define the possible examples for the endpoints, as found in the original definition.

View solution in original post

1 REPLY 1
Staff

Re: Swagger codegen/Swagger editor don't want to generate example

 I am not sure I fully understand the issue, however if I get this correctly you are generating a spring server stub using the "spring" generator; and your second screenshot is the swagger-ui embedded into the result code. Each generator behaves differently and has different capabilities, in this case the generated server code is using springfox project to expose a Swagger definition resolved from the Api/Controller code. The generated code doesn't add for example annotations to define the possible examples for the endpoints, as found in the original definition.

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements