BAEL-4345 add code for the swagger specify two responses with the same code article
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.tworesponses;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String args[]) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.tworesponses;
|
||||
|
||||
import org.springdoc.core.SpringDocConfigProperties;
|
||||
import org.springdoc.core.SpringDocConfiguration;
|
||||
import org.springdoc.core.providers.ObjectMapperProvider;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class Config {
|
||||
|
||||
@Bean
|
||||
SpringDocConfiguration springDocConfiguration() {
|
||||
return new SpringDocConfiguration();
|
||||
}
|
||||
|
||||
@Bean
|
||||
SpringDocConfigProperties springDocConfigProperties() {
|
||||
return new SpringDocConfigProperties();
|
||||
}
|
||||
|
||||
@Bean
|
||||
ObjectMapperProvider objectMapperProvider(SpringDocConfigProperties springDocConfigProperties) {
|
||||
return new ObjectMapperProvider(springDocConfigProperties);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
springdoc.api-docs.enabled=false
|
||||
springdoc.swagger-ui.url=/api_3.yaml
|
||||
@@ -0,0 +1,45 @@
|
||||
swagger: 2.0.0
|
||||
info:
|
||||
title: Demo api
|
||||
description: Demo api for the article 'specify two responses with same code based on optional parameter'
|
||||
version: 0.1.0
|
||||
paths:
|
||||
/vehicle:
|
||||
get:
|
||||
responses:
|
||||
'200':
|
||||
description: Get a vehicle. Can contain either a Car or a Bike
|
||||
schema:
|
||||
$ref: '#/definitions/CarOrBike'
|
||||
examples:
|
||||
application/json:
|
||||
owner: baeldung
|
||||
plate: AEX305
|
||||
speed:
|
||||
definitions:
|
||||
Car:
|
||||
type: object
|
||||
properties:
|
||||
owner:
|
||||
type: string
|
||||
plate:
|
||||
type: string
|
||||
Bike:
|
||||
type: object
|
||||
properties:
|
||||
owner:
|
||||
type: string
|
||||
speed:
|
||||
type: integer
|
||||
CarOrBike:
|
||||
description: a car will have an owner and a plate, whereas a bike has an owner and a speed
|
||||
type: object
|
||||
required:
|
||||
- owner
|
||||
properties:
|
||||
owner:
|
||||
type: string
|
||||
plate:
|
||||
type: string
|
||||
speed:
|
||||
type: integer
|
||||
@@ -0,0 +1,44 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Demo api
|
||||
description: Demo api for the article 'specify two responses with same code based on optional parameter'
|
||||
version: 0.1.0
|
||||
paths:
|
||||
/vehicle:
|
||||
get:
|
||||
responses:
|
||||
'200':
|
||||
description: Get a vehicle
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/Car'
|
||||
- $ref: '#/components/schemas/Bike'
|
||||
examples:
|
||||
car:
|
||||
summary: an example of car
|
||||
value:
|
||||
owner: baeldung
|
||||
plate: AEX305
|
||||
bike:
|
||||
summary: an example of bike
|
||||
value:
|
||||
owner: john doe
|
||||
speed: 25
|
||||
components:
|
||||
schemas:
|
||||
Car:
|
||||
type: object
|
||||
properties:
|
||||
owner:
|
||||
type: string
|
||||
plate:
|
||||
type: string
|
||||
Bike:
|
||||
type: object
|
||||
properties:
|
||||
owner:
|
||||
type: string
|
||||
speed:
|
||||
type: integer
|
||||
Reference in New Issue
Block a user