-
I am trying out this guide https://guides.micronaut.io/latest/micronaut-openapi-generator-server-maven-java.html to see api first development and how swagger will look like. But doing api first approach the swagger ui shows all responses/descriptions clubbed together under 200 code even though I have multiple responses defined in the spec as follows. Ideally there should be separate seciton for each responses. Looks like a bug ? "200":
description: OK Account Resp (status code 200) or Bad Request (status code
400) or Internal Server Error (status code 500) Following is my myspec.yml. openapi: 3.0.1
info:
title: Banking API Specification for account operations
description: |-
A simple banking API that allows two operations:
- get account balance given account number
- deposit amount to a account
version: 1.0-SNAPSHOT
servers:
- url: https://testenvironment.org/api/v1
- url: https://prodenvironment.org/api/v1
tags:
- name: accounts
description: Operations between bank accounts
paths:
/account:
get:
tags:
- accounts
summary: Get account information
description: Get account information using account number
operationId: getAccount
parameters:
- name: accNumber
in: query
schema:
type: string
minLength: 3
responses:
200:
description: OK Account Resp
400:
description: Bad Request
content:
application/json:
schema:
type: object
properties:
error:
type: string
500:
description: Internal Server Error
content:
application/json:
schema:
type: object
properties:
error:
type: string
/account/deposit:
post:
tags:
- accounts
summary: Deposit amount to account
description: Initiates a deposit operation of a desired amount to the account specified
operationId: depositToAccount
requestBody:
description: Account number and desired amount to deposit
content:
application/json:
schema:
$ref: '#/components/schemas/DepositRequest'
required: true
responses:
204:
description: Success
400:
description: Request missing required params
content:
application/json:
schema:
type: object
properties:
error:
type: string
500:
description: Internal Server Error
content:
application/json:
schema:
type: object
properties:
error:
type: string
components:
schemas:
Account:
type: object
properties:
balance:
type: number
AccountNotFoundError:
type: object
properties:
message:
type: string
DepositRequest:
type: object
properties:
accountNumber:
type: string
depositAmount:
type: number And the generated final resolved yaml from swagger UI is as follows. openapi: 3.0.1
info:
title: micronautguide
version: 1.0.0
paths:
/account:
get:
summary: Get account information
description: Get account information Get account information using account number
operationId: getAccount
parameters:
- name: accNumber
in: query
description: (optional)
explode: false
schema:
type: string
nullable: true
responses:
"200":
description: OK Account Resp (status code 200) or Bad Request (status code
400) or Internal Server Error (status code 500)
/account/deposit:
post:
summary: Deposit amount to account
description: Deposit amount to account Initiates a deposit operation of a desired
amount to the account specified
operationId: depositToAccount
requestBody:
description: Account number and desired amount to deposit (required)
content:
application/json:
schema:
$ref: "#/components/schemas/DepositRequest"
required: true
responses:
"200":
description: Success (status code 204) or Request missing required params
(status code 400) or Internal Server Error (status code 500)
components:
schemas:
DepositRequest:
type: object
properties:
accountNumber:
type: string
nullable: true
depositAmount:
type: number
nullable: true
description: DepositRequest |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
Need a sample reproducer for your case, because you didn't explain many details in your question, like setting for openapi-generator and how you create second swagger file. Please, create a sample project and I will take a look |
Beta Was this translation helpful? Give feedback.
-
Any update on this please ? |
Beta Was this translation helpful? Give feedback.
-
@subash89 Just add ![]() And you will see what you want: ![]() ![]() Hmm... but I found one small bug in second operation: ![]() As you see, response with status |
Beta Was this translation helpful? Give feedback.
-
Fixed this bug here: #2331 |
Beta Was this translation helpful? Give feedback.
-
@subash89 but here's what I don't understand: why are you generating an openapi specification from the generated code if you already have a file with an openapi specification? |
Beta Was this translation helpful? Give feedback.
@subash89 but here's what I don't understand: why are you generating an openapi specification from the generated code if you already have a file with an openapi specification?