-
Notifications
You must be signed in to change notification settings - Fork 4
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
[#17] Added api-spec to the project and the maven plugin to generate server boilerplate #42
Changes from all commits
5ff9ea8
a84e824
d5b8ca5
02deda7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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> | ||
Comment on lines
+68
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before anyone asks about this, version 4.3.1 of the open api generator adds an usused import for this library in the models. It is a known bug which is tracked here OpenAPITools/openapi-generator#5690. I personally tested with version 5.0.0-beta2 and the bug is fixed in that version, but I'd rather not depend on a beta version of a library. Another option would be to downgrade to an earlier version where the bug does not exist, but then we risk missing more recent features/bug fixes. |
||
</dependencies> | ||
|
||
<build> | ||
|
@@ -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> | ||
|
||
|
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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we decided on using universally unique identifier (uuid)? Why not just an id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's pretty much just what I've been doing from experience. Another idea was to use the database IDs, but I figured that would be error prone. Do you have any other ideas?