Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change api spec file to openapi v3 #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
119 changes: 119 additions & 0 deletions user-service-contract/api/simple-inventory.yaml
@@ -0,0 +1,119 @@
openapi: 3.0.0
# Added by API Auto Mocking Plugin
servers:
- description: SwaggerHub API Auto Mocking
url: https://virtserver.swaggerhub.com/robincomcarde/demo-api/1.0.0
info:
description: This is a simple API
version: "1.0.0"
title: Simple Inventory API
contact:
email: you@your-company.com
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: admins
description: Secured Admin-only calls
- name: developers
description: Operations available to regular developers
paths:
/inventory:
get:
tags:
- developers
summary: searches inventory
operationId: searchInventory
description: |
By passing in the appropriate options, you can search for
available inventory in the system
parameters:
- in: query
name: searchString
description: pass an optional search string for looking up inventory
required: false
schema:
type: string
- in: query
name: skip
description: number of records to skip for pagination
schema:
type: integer
format: int32
minimum: 0
- in: query
name: limit
description: maximum number of records to return
schema:
type: integer
format: int32
minimum: 0
maximum: 50
responses:
'200':
description: search results matching criteria
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/InventoryItem'
'400':
description: bad input parameter
post:
tags:
- admins
summary: adds an inventory item
operationId: addInventory
description: Adds an item to the system
responses:
'201':
description: item created
'400':
description: 'invalid input, object invalid'
'409':
description: an existing item already exists
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/InventoryItem'
description: Inventory item to add
components:
schemas:
InventoryItem:
type: object
required:
- id
- name
- manufacturer
- releaseDate
properties:
id:
type: string
format: uuid
example: d290f1ee-6c54-4b01-90e6-d701748f0851
name:
type: string
example: Widget Adapter
releaseDate:
type: string
format: date-time
example: '2016-08-29T09:12:33.001Z'
manufacturer:
$ref: '#/components/schemas/Manufacturer'
Manufacturer:
required:
- name
properties:
name:
type: string
example: ACME Corporation
homePage:
type: string
format: url
example: 'https://www.acme-corp.com'
phone:
type: string
example: 408-867-5309
type: object
34 changes: 22 additions & 12 deletions user-service-contract/build.gradle
Expand Up @@ -3,16 +3,20 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("io.swagger:swagger-codegen:2.3.1")
classpath('io.swagger.codegen.v3:swagger-codegen-maven-plugin:3.0.16')
}
}

apply plugin: 'base'

group = 'com.arnoldgalovics.blog'

import io.swagger.codegen.DefaultGenerator
import io.swagger.codegen.config.CodegenConfigurator

import io.swagger.codegen.v3.CodegenConfigLoader
import io.swagger.codegen.v3.DefaultGenerator
import io.swagger.codegen.v3.ClientOptInput
import io.swagger.codegen.v3.ClientOpts
import io.swagger.v3.parser.OpenAPIV3Parser

subprojects {
repositories {
Expand Down Expand Up @@ -58,7 +62,7 @@ subprojects {
ext.appName = 'user-service'
ext.apiPackage = 'com.arnoldgalovics.blog.userservice.api'
ext.modelPackage = 'com.arnoldgalovics.blog.userservice.model'
ext.swaggerFile = "${rootDir}/api/swagger.yml"
ext.swaggerFile = "${rootDir}/api/simple-inventory.yaml"

project("${rootProject.appName}-server") { // user-service-server

Expand All @@ -68,21 +72,27 @@ project("${rootProject.appName}-server") { // user-service-server
compile('io.springfox:springfox-swagger2:2.7.0')
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

// Actual task for generating the server
task generateServer {
doLast {
def config = new CodegenConfigurator()
config.setLang("spring")
config.setApiPackage(rootProject.apiPackage) // Package to be used for the API interfaces
config.setModelPackage(rootProject.modelPackage) // Package to be used for the API models
config.setInputSpec(rootProject.swaggerFile.toString()) // The swagger API file
config.setOutputDir(project.buildDir.toString()) // The output directory, user-service-contract/build/user-service-server/
config.setAdditionalProperties([
def openAPI = new OpenAPIV3Parser().read(rootProject.swaggerFile.toString(), null, null)
def clientOpts = new ClientOptInput().openAPI(openAPI)
def codegenConfig = CodegenConfigLoader.forName('spring')
codegenConfig.setOutputDir(project.buildDir.toString())
clientOpts.setConfig(codegenConfig)
def clientOps = new ClientOpts()
clientOps.setProperties([
'dateLibrary' : 'java8', // Date library to use
'useTags' : 'true', // Use tags for the naming
'interfaceOnly' : 'true' // Generating the Controller API interface and the models only
])
new DefaultGenerator().opts(config.toClientOptInput()).generate() // Executing the generation
clientOpts.setOpts(clientOps)

def generator = new DefaultGenerator().opts(clientOpts)
generator.generate() // Executing the generation
}
}

Expand Down
Empty file modified user-service-contract/gradlew 100644 → 100755
Empty file.