Added api response documentation

This commit is contained in:
Jim Martens 2020-07-11 21:00:28 +02:00
parent dcf5708d32
commit c3c20d9ecf
1 changed files with 95 additions and 18 deletions

View File

@ -1,17 +1,18 @@
package de.twomartens.oparlservice.control;
import de.twomartens.oparlservice.entity.*;
import de.twomartens.oparlservice.entity.System;
import de.twomartens.oparlservice.entity.*;
import de.twomartens.oparlservice.service.OParlService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import java.util.List;
@Slf4j
@RestController
@RequestMapping(path = "/v1.1")
@ -23,21 +24,34 @@ public class OParlController {
}
@GetMapping("/")
@Operation(summary = "System information", description = "returns information about the OParl system")
@Operation(summary = "System information", description = "returns information about the OParl system", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = System.class)
))
})
public System system() {
log.info("method invoked /v1.1");
return service.getSystem();
}
@GetMapping("/bodies")
@Operation(summary = "List of available bodies", description = "returns a list of available bodies in this OParl system")
@Operation(summary = "List of available bodies",
description = "returns a list of available bodies in this OParl system", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class)))
})
public ObjectList<Body> bodies() {
log.info("method invoked /v1.1/bodies");
return this.service.getBodies();
}
@GetMapping("/body/{id}")
@Operation(summary = "information about body", description = "returns information about the requested body")
@Operation(summary = "information about body", description = "returns information about the requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Body.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public Body body(
@PathVariable
@Parameter(description = "body ID", example = "0")
@ -49,7 +63,12 @@ public class OParlController {
}
@GetMapping("/term/{id}")
@Operation(summary = "information about legislative term", description = "returns information about the requested legislative term")
@Operation(summary = "information about legislative term", description = "returns information about the requested legislative term", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = LegislativeTerm.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public LegislativeTerm legislativeTerm(
@PathVariable
@Parameter(description = "legislative term ID", example = "21")
@ -61,7 +80,12 @@ public class OParlController {
}
@GetMapping("/body/{id}/organizations")
@Operation(summary = "List of all organizations in body", description = "returns a list of all organizations in requested body")
@Operation(summary = "List of all organizations in body", description = "returns a list of all organizations in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<Organization> organizationsInBody(
@PathVariable
@Parameter(description = "body ID", example = "0")
@ -73,7 +97,12 @@ public class OParlController {
}
@GetMapping("/organization/{id}")
@Operation(summary = "information about organization", description = "returns the requested organization")
@Operation(summary = "information about organization", description = "returns the requested organization", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Organization.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public Organization organization(
@PathVariable
@Parameter(description = "organization ID", example = "0")
@ -85,7 +114,12 @@ public class OParlController {
}
@GetMapping("/body/{id}/persons")
@Operation(summary = "List of all persons in body", description = "returns a list of all persons in requested body")
@Operation(summary = "List of all persons in body", description = "returns a list of all persons in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<Person> persons(
@PathVariable
@Parameter(description = "body ID", example = "0")
@ -97,7 +131,12 @@ public class OParlController {
}
@GetMapping("/person/{id}")
@Operation(summary = "information about person", description = "returns the requested person")
@Operation(summary = "information about person", description = "returns the requested person", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Person.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public Person person(
@PathVariable
@Parameter(description = "person ID", example = "0")
@ -109,7 +148,12 @@ public class OParlController {
}
@GetMapping("/body/{id}/memberships")
@Operation(summary = "List of all memberships in body", description = "returns a list of all memberships in requested body")
@Operation(summary = "List of all memberships in body", description = "returns a list of all memberships in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<Membership> membershipsInBody(
@PathVariable
@Parameter(description = "body ID", example = "0")
@ -121,7 +165,13 @@ public class OParlController {
}
@GetMapping("/organization/{id}/memberships")
@Operation(summary = "List of all memberships in organization", description = "returns a list of all memberships in requested organization")
@Operation(summary = "List of all memberships in organization",
description = "returns a list of all memberships in requested organization", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<Membership> membershipsInOrganization(
@PathVariable
@Parameter(description = "organization ID", example = "0")
@ -133,7 +183,12 @@ public class OParlController {
}
@GetMapping("/membership/{id}")
@Operation(summary = "information about membership", description = "returns the requested membership")
@Operation(summary = "information about membership", description = "returns the requested membership", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Membership.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public Membership membership(
@PathVariable
@Parameter(description = "membership ID", example = "0")
@ -145,7 +200,13 @@ public class OParlController {
}
@GetMapping("/body/{id}/meetings")
@Operation(summary = "List of all meetings in body", description = "returns a list of all meetings in requested body")
@Operation(summary = "List of all meetings in body",
description = "returns a list of all meetings in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<Meeting> meetingsInBody(
@PathVariable
@Parameter(description = "body ID", example = "0")
@ -157,7 +218,13 @@ public class OParlController {
}
@GetMapping("/organization/{id}/meetings")
@Operation(summary = "List of all meetings in organization", description = "returns a list of all meetings in requested organization")
@Operation(summary = "List of all meetings in organization",
description = "returns a list of all meetings in requested organization", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<Meeting> meetingsInOrganization(
@PathVariable
@Parameter(description = "organization ID", example = "0")
@ -169,7 +236,12 @@ public class OParlController {
}
@GetMapping("/meeting/{id}")
@Operation(summary = "information about meeting", description = "returns the requested meeting")
@Operation(summary = "information about meeting", description = "returns the requested meeting", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Meeting.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public Meeting meeting(
@PathVariable
@Parameter(description = "meeting ID", example = "0")
@ -181,7 +253,12 @@ public class OParlController {
}
@GetMapping("/agendaItem/{id}")
@Operation(summary = "information about agenda item", description = "returns the requested agenda item")
@Operation(summary = "information about agenda item", description = "returns the requested agenda item", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Body.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public AgendaItem agendaItem(
@PathVariable
@Parameter(description = "agendaItem ID", example = "0")