Skip to content

Commit 9ed6138

Browse files
committed
chore: use request body with name for record text in validation endpoint
1 parent 6f29d42 commit 9ed6138

3 files changed

Lines changed: 396 additions & 381 deletions

File tree

src/main/java/massbank_export_api/api/ValidateApiDelegateImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package massbank_export_api.api;
22

33
import massbank.RecordParser;
4+
import massbank_export_api.model.Validation;
45
import massbank_export_api.model.ValidationError;
56
import org.petitparser.context.Result;
67
import org.springframework.context.annotation.Primary;
@@ -22,14 +23,16 @@ public ValidateApiDelegateImpl() {
2223
}
2324

2425
@Override
25-
public ResponseEntity<Void> validatePost(final String body) {
26-
if (body == null || body.trim().isEmpty()) {
26+
public ResponseEntity<Void> validatePost(Validation validation) {
27+
if (validation == null || validation.getText() == null) {
2728
return ResponseEntity.badRequest().build();
2829
}
2930

31+
final String recordText = validation.getText();
32+
3033
ResponseEntity<ValidationError> respWithBody;
3134
final ValidationError error = new ValidationError();
32-
final Result result = recordParser.parse(body);
35+
final Result result = recordParser.parse(recordText);
3336
if (result.isSuccess()) {
3437
error.setMessage("Record is valid.");
3538
error.setLine(null);
@@ -41,7 +44,7 @@ public ResponseEntity<Void> validatePost(final String body) {
4144
final String message = result.getMessage();
4245
final int pos = result.getPosition();
4346

44-
final String[] tokens = body.split("\\n");
47+
final String[] tokens = recordText.split("\\n");
4548
int offset = 0;
4649
int lineNumber = 1;
4750
int col = 0;

src/main/resources/openapi.yaml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
openapi: 3.0.3
22
info:
33
title: Export MassBank content in different formats
4-
description:
5-
This microservice converts MassBank records into a number of different other formats.
4+
description: This microservice converts MassBank records into a number of different other formats.
65
version: "0.1"
76
servers:
87
- url: http://localhost:8080
@@ -109,12 +108,9 @@ paths:
109108
requestBody:
110109
required: true
111110
content:
112-
text/plain; charset=utf-8:
111+
application/json:
113112
schema:
114-
type: string
115-
example: |
116-
ACCESSION: MSBNK-IPB_Halle-PB001341
117-
RECORD_TITLE: ...
113+
$ref: "#/components/schemas/validation"
118114
responses:
119115
"200":
120116
description: Record is valid.
@@ -159,6 +155,16 @@ components:
159155
format:
160156
$ref: "#/components/schemas/format"
161157

158+
validation:
159+
description: a single record as plain text
160+
type: object
161+
properties:
162+
text:
163+
type: string
164+
example: |
165+
ACCESSION: MSBNK-IPB_Halle-PB001341
166+
RECORD_TITLE: ...
167+
162168
validation_error:
163169
description: Detailed validation errors for an invalid record.
164170
type: object
@@ -171,4 +177,4 @@ components:
171177
example: 12
172178
column:
173179
type: integer
174-
example: 5
180+
example: 5

0 commit comments

Comments
 (0)