diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggeryml/SwaggerYMLApplication.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggeryml/SwaggerYMLApplication.java new file mode 100644 index 000000000000..4963d3176e39 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggeryml/SwaggerYMLApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.swaggeryml; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; + +@SpringBootApplication +public class SwaggerYMLApplication { + public static void main(String[] args) { + new SpringApplicationBuilder(SwaggerYMLApplication.class) + .properties("spring.config.name=application-yml") + .run(args); + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/resources/application-yml.properties b/spring-boot-modules/spring-boot-springdoc/src/main/resources/application-yml.properties new file mode 100644 index 000000000000..dbb92333302e --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/resources/application-yml.properties @@ -0,0 +1,6 @@ +spring.application.name=swaggeryml +springdoc.api-docs.enabled=true +springdoc.api-docs.path=/v3/api-docs +springdoc.api-docs.resolve-schema-properties=false +springdoc.swagger-ui.url=/openapi.yml +springdoc.swagger-ui.path=/swagger-ui.html diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/resources/static/components/schemas/Student.yml b/spring-boot-modules/spring-boot-springdoc/src/main/resources/static/components/schemas/Student.yml new file mode 100644 index 000000000000..bc6fbc708d3a --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/resources/static/components/schemas/Student.yml @@ -0,0 +1,9 @@ +type: object +properties: + id: + type: integer + format: int64 + name: + type: string + rollNo: + type: string \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/resources/static/openapi.yml b/spring-boot-modules/spring-boot-springdoc/src/main/resources/static/openapi.yml new file mode 100644 index 000000000000..04926c97b62d --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/resources/static/openapi.yml @@ -0,0 +1,58 @@ +openapi: 3.1.0 +info: + title: Student API + description: Following documentation explain the API's supported by the [student server](http://localhost:8080). + version: 1.1.9 +servers: + - url: http://localhost:8080/v1 + description: Prod server + variables: + region: + default: us-west + enum: + - us-west + - us-east + - url: http://localhost:8080/test + description: Test server +paths: + /students: + get: + tags: + - Students + summary: Returns all the students. + description: Following path gives all the data related to students + responses: + "200": + description: A JSON array of student objects + content: + application/json: + schema: + type: array + items: + $ref: './components/schemas/Student.yml' + /students/{id}: + get: + tags: + - Students + summary: Gets a student by ID. + description: > + Gives the details of specific student based on **ID** + operationId: getStudentById + parameters: + - name: id + in: path + description: Student ID + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Successful operation + content: + application/json: + schema: + $ref: './components/schemas/Student.yml' +externalDocs: + description: Learn more about student operations provided by this API. + url: http://localhost:8080/swagger-ui/index.html \ No newline at end of file