Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion application/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'org.springframework.boot'
id 'org.openapi.generator' version '4.3.1'
}

configurations {
Expand Down Expand Up @@ -40,4 +41,19 @@ dependencies {

test {
useJUnitPlatform()
}
}

// For Maven see:
// https://reflectoring.io/spring-boot-openapi/
// https://github.com/thombergs/code-examples/tree/master/spring-boot/spring-boot-openapi

openApiGenerate {
generatorName = "spring"
inputSpec = "$projectDir/src/main/resources/api.yaml"
outputDir = "$buildDir/generated/api"
apiPackage = "com.example.demo.api"
invokerPackage = "com.example.demo.invoker"
modelPackage = "com.example.demo.model"
}

compileJava.dependsOn tasks.openApiGenerate
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.example.demo.rest;

import java.util.concurrent.atomic.AtomicLong;

import com.Greeting;
import com.example.demo.Greeting;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

@GetMapping("/")
@GetMapping("/greeting")
public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
return Greeting.builder()
.value("Hello World")
Expand Down
146 changes: 146 additions & 0 deletions application/src/main/resources/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
openapi: 3.0.2
info:
title: Reflectoring
description: "???"
termsOfService: http://swagger.io/terms/
contact:
email: maksim.sendetckii@de.sii.group
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0-SNAPSHOT
externalDocs:
description: Find out more about Reflectoring
url: https://reflectoring.io/about/
servers:
- url: https://reflectoring.swagger.io/v2
tags:
- name: user
description: Operations about user
externalDocs:
description: Find out more about our store
url: http://swagger.io
paths:
/user:
post:
tags:
- user
summary: Create user
description: Create user functionality
operationId: createUser
requestBody:
description: Created user object
content:
'*/*':
schema:
$ref: '#/components/schemas/User'
required: true
responses:
default:
description: successful operation
content: {}
x-codegen-request-body-name: body
/user/{username}:
get:
tags:
- user
summary: Get user by user name
operationId: getUserByName
parameters:
- name: username
in: path
description: 'The name that needs to be fetched. Use user1 for testing. '
required: true
schema:
type: string
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/User'
404:
description: User not found
content: {}
put:
tags:
- user
summary: Updated user
description: This can only be done by the logged in user.
operationId: updateUser
parameters:
- name: username
in: path
description: name that need to be updated
required: true
schema:
type: string
requestBody:
description: Updated user object
content:
'*/*':
schema:
$ref: '#/components/schemas/User'
required: true
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/User'
400:
description: Invalid user supplied
content: {}
404:
description: User not found
content: {}
x-codegen-request-body-name: body
delete:
tags:
- user
summary: Delete user
description: This can only be done by the logged in user.
operationId: deleteUser
parameters:
- name: username
in: path
description: The name that needs to be deleted
required: true
schema:
type: string
responses:
201:
description: operation successful
content: {}
400:
description: Invalid username supplied
content: {}
404:
description: User not found
content: {}
components:
schemas:
User:
type: object
properties:
id:
type: integer
format: int64
username:
type: string
firstName:
type: string
lastName:
type: string
email:
type: string
password:
type: string
phone:
type: string
userStatus:
type: integer
description: User Status
format: int32
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ subprojects {

}
}

dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com;
package com.example.demo;

import lombok.Builder;
import lombok.NonNull;
Expand All @@ -9,4 +9,4 @@
public class Greeting {
@NonNull
String value;
}
}
1 change: 1 addition & 0 deletions domain-entities/src/test/java/com/GreetingTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com;

import com.example.demo.Greeting;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down