Skip to content

Commit

Permalink
[#17] Added api-spec to the project and the maven plugin to generate …
Browse files Browse the repository at this point in the history
…server boilerplate (#42)

* Added api-spec to the project and the maven plugin to generate server boilerplate

* Added empty line

* Changed the post request to remove IP and port number

* Renamed some entities, sender -> encoder, receiver -> decoder
  • Loading branch information
FGRCL authored Sep 27, 2020
1 parent d042997 commit 8fd0e2c
Show file tree
Hide file tree
Showing 4 changed files with 344 additions and 0 deletions.
234 changes: 234 additions & 0 deletions service/switchboardapp/contracts/api-spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
openapi: 3.0.0
info:
version: 1.0.0
title: 'Switchboard API'
description: 'API for the switchboard service'

servers:
- url: https://placeholder.com/v1/
description: Test environment

paths:
/Encoders:
get:
operationId: getEncoders
description: Get a list of available encoders
tags:
- Encoders
responses:
'200':
description: Successful retrieval of encoder list
content:
application/json:
schema:
$ref: '#/components/schemas/EncoderUuids'
post:
operationId: createEncoder
description: Create a new encoder client
tags:
- Encoders
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateEncoderRequest'
responses:
'200':
description: Successful creation the encoder
/Encoders/{uuid}:
get:
operationId: getEncoderById
description: Retrieve a specific encoder
tags:
- Encoders
parameters:
- $ref: '#/components/parameters/EncoderId'
responses:
'200':
description: Successful retrieval of the encoder
content:
application/json:
schema:
$ref: '#/components/schemas/Encoder'
put:
operationId: updateEncoder
description: Update a encoder's definition
tags:
- Encoders
parameters:
- $ref: '#/components/parameters/EncoderId'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Encoder'
responses:
'200':
description: Successful update of the Encoder
delete:
operationId: deleteEncoder
description: Delete a encoder
tags:
- Encoders
parameters:
- $ref: '#/components/parameters/EncoderId'
responses:
'200':
description: Successful deletion of the encoder

/Decoders:
get:
operationId: getDecoders
description: Get a list of available decoders
tags:
- Decoders
responses:
'200':
description: Successful retrieval of decoder list
content:
application/json:
schema:
$ref: '#/components/schemas/DecoderUuids'
post:
operationId: createDecoder
description: Create a new decoder client
tags:
- Decoders
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateDecoderRequest'
responses:
'200':
description: Successful creation of the decoder
/Decoders/{uuid}:
get:
operationId: getDecoderById
description: Retrieve a specific decoder
tags:
- Decoders
parameters:
- $ref: '#/components/parameters/DecoderId'
responses:
'200':
description: Successful retrieval of the decoder
content:
application/json:
schema:
$ref: '#/components/schemas/Decoder'
put:
operationId: updateDecoder
description: Update a decoder's definition
tags:
- Decoders
parameters:
- $ref: '#/components/parameters/DecoderId'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Decoder'
responses:
'200':
description: Successful update of the decoder
delete:
operationId: deleteDecoder
description: Delete a decoder
tags:
- Decoders
parameters:
- $ref: '#/components/parameters/DecoderId'
responses:
'200':
description: Successful deletion of the decoder

components:
schemas:
EncoderUuids:
description: A list of UUIDs
type: array
items:
type: string
example: ['0e4e430f-8b9c-47da-b9af-7ef9cfb13e9e']
Encoder:
description: A client that sends a video stream
properties:
displayName:
type: string
example: 'Camera 1B'
ip:
type: string
example: '120.45.43.24'
port:
type: string
example: '31507'
serialNumber:
type: string
example: 'BtmC8ckj'
CreateEncoderRequest:
description: A client that sends a video stream
properties:
displayName:
type: string
example: 'Camera 1B'
serialNumber:
type: string
example: 'BtmC8ckj'
DecoderUuids:
description: A list of decoder UUIDs
type: array
items:
type: string
example: ['1ea52153-c196-4cc6-8d9f-714248abf31c']
Decoder:
description: A client that receives a video stream
properties:
displayName:
type: string
example: 'Decoder 3F'
ip:
type: string
example: '45.100.56.135'
port:
type: string
example: '16591'
serialNumber:
type: string
example: 'v7BM3ejS'
CreateDecoderRequest:
description: Body for the creation of a decoder object
properties:
displayName:
type: string
example: 'Decoder 3F'
serialNumber:
type: string
example: 'v7BM3ejS'
parameters:
EncoderId:
in: path
name: uuid
required: true
description: The UUID of a Encoder
schema:
type: string
example: '0e4e430f-8b9c-47da-b9af-7ef9cfb13e9e'
DecoderId:
in: path
name: uuid
required: true
description: The UUID of a decoder
schema:
type: string
example: '1ea52153-c196-4cc6-8d9f-714248abf31c'

tags:
- name: Encoders
description: Encoders endpoints
- name: Decoders
description: Decoders endpoints
38 changes: 38 additions & 0 deletions service/switchboardapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

<properties>
<java.version>11</java.version>
<springfox-version>2.8.0</springfox-version>
<openapi-generator-version>4.3.1</openapi-generator-version>
<openapi-jackson-nullable-version>0.2.1</openapi-jackson-nullable-version>
</properties>

<dependencies>
Expand Down Expand Up @@ -55,6 +58,19 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator</artifactId>
<version>${openapi-generator-version}</version>
</dependency>

<!--TODO remove this dependency when org.openapitools.openapi-generator releases version 5.0.0-->
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>${openapi-jackson-nullable-version}</version>
</dependency>
</dependencies>

<build>
Expand All @@ -63,6 +79,28 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/contracts/api-spec.yaml</inputSpec>
<generatorName>spring</generatorName>
<configOptions>
<sourceFolder>src/java/main</sourceFolder>
<interfaceOnly>true</interfaceOnly>
<openApiNullable>false</openApiNullable>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.switchboard.app.controller;

import org.openapitools.api.DecodersApi;
import org.openapitools.model.CreateDecoderRequest;
import org.openapitools.model.Decoder;
import org.springframework.http.ResponseEntity;

import javax.validation.Valid;
import java.util.List;

public class DecodersController implements DecodersApi {
@Override
public ResponseEntity<List<String>> getDecoders() {
return null;
}

@Override
public ResponseEntity<Void> createDecoder(@Valid CreateDecoderRequest createDecoderRequest) {
return null;
}

@Override
public ResponseEntity<Decoder> getDecoderById(String uuid) {
return null;
}

@Override
public ResponseEntity<Void> updateDecoder(String uuid, @Valid Decoder decoder) {
return null;
}

@Override
public ResponseEntity<Void> deleteDecoder(String uuid) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.switchboard.app.controller;

import org.openapitools.api.EncodersApi;
import org.openapitools.model.CreateEncoderRequest;
import org.openapitools.model.Encoder;
import org.springframework.http.ResponseEntity;

import javax.validation.Valid;
import java.util.List;

public class EncodersController implements EncodersApi {
@Override
public ResponseEntity<List<String>> getEncoders() {
return null;
}

@Override
public ResponseEntity<Void> createEncoder(@Valid CreateEncoderRequest createEncoderRequest) {
return null;
}

@Override
public ResponseEntity<Encoder> getEncoderById(String uuid) {
return null;
}

@Override
public ResponseEntity<Void> updateEncoder(String uuid, @Valid Encoder encoder) {
return null;
}

@Override
public ResponseEntity<Void> deleteEncoder(String uuid) {
return null;
}
}

0 comments on commit 8fd0e2c

Please sign in to comment.