Forum Discussion

SriniMarva27's avatar
SriniMarva27
Occasional Contributor
3 years ago

Schema displayed in https://editor.swagger.io/ is not showing in swagger ui

I am trying to generate a spring server using a yaml file on https://editor.swagger.io/, but after I generate my spring server and I execute my spring boot application, I could not see a schema named 'error' referenced under response code 400. Below is the contents of my yaml file

 

openapi: 3.0.0
info:
title: Dealer Management System
description: REST APIs to manage dealers
version: 1.0.0
contact:
name: Srinivasan Ramu
email: srinimarva@gmail.com
tags:
- name: Dealer
description: REST endpoints to manage dealers
paths:
/dealers/addNew:
post:
summary: Add new dealer
description: To add a new dealer
tags:
- Dealer
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/dealer"
responses:
"200":
description: Dealer added successfully
content:
application/json:
schema:
$ref: "#/components/schemas/dealer"
"400":
description: Bad request
content:
application/json:
schema:
$ref: "#/components/schemas/error"
components:
schemas:
dealer:
type: object
properties:
dealerId:
type: integer
description: Unique id to represent a dealer
example: 34089
dealerName:
type: string
description: Name of the dealer
example: Town North Mazda
dealerAddress:
type: string
description: Address of the dealer
example: 1715 North Central Expressway
dealerCity:
type: string
description: City where the dealer is located
example: Richardson
dealerState:
type: string
description: State where the dealer is located
example: TX
dealerZip:
type: integer
description: Zip code where the dealer is located
example: 75080
error:
type: object
properties:
id:
type: string
description: Unique id to represent a type of error
example: bad_request
message:
type: string
description: Meaningful message about what went wrong
example: dealer id already exists

 

Steps to reproduce the issue

  1. Go to https://editor.swagger.io/
  2. Copy paste my yaml file and witness there are two schemas displayed - dealer and error
  3. Click Generate Server -> spring menu option
  4. Unzip the downloaded project and import the Maven project into (Spring Tools Suite) STS application
  5. Run the spring boot project and go to http://localhost:8080/swagger-ui/index.html
  6. Go to schemas section and check if you can see both dealer and error models

Please help me understand on what mistake am I making while generating my spring boot server?

No RepliesBe the first to reply