Skip to content

Commit b5c6e9c

Browse files
initial commit
1 parent 3302750 commit b5c6e9c

5 files changed

Lines changed: 53 additions & 2 deletions

File tree

gateway-api/openapi.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,30 @@ paths:
238238
diagnostics:
239239
type: string
240240
example: "Patient not found"
241+
'415':
242+
description: Unsupported Media Type"
243+
content:
244+
application/fhir+json:
245+
schema:
246+
type: object
247+
properties:
248+
resourceType:
249+
type: string
250+
example: "OperationOutcome"
251+
issue:
252+
type: array
253+
items:
254+
type: object
255+
properties:
256+
severity:
257+
type: string
258+
example: "error"
259+
code:
260+
type: string
261+
example: "invalid"
262+
diagnostics:
263+
type: string
264+
example: 'Unsupported "Content-Type". Expected "application/fhir+json".'
241265
'500':
242266
description: Internal server error
243267
content:

gateway-api/src/gateway_api/common/error.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
from dataclasses import dataclass
2-
from http.client import BAD_GATEWAY, BAD_REQUEST, INTERNAL_SERVER_ERROR, NOT_FOUND
2+
from http.client import (
3+
BAD_GATEWAY,
4+
BAD_REQUEST,
5+
INTERNAL_SERVER_ERROR,
6+
NOT_FOUND,
7+
UNSUPPORTED_MEDIA_TYPE,
8+
)
39

410
from fhir.stu3 import Issue, IssueCode, IssueSeverity, OperationOutcome
511

@@ -114,3 +120,10 @@ class UnexpectedError(AbstractCDGError):
114120
status_code = INTERNAL_SERVER_ERROR
115121
severity = IssueSeverity.ERROR
116122
error_code = IssueCode.EXCEPTION
123+
124+
125+
class UnsupportedMediaTypeError(AbstractCDGError):
126+
_message = "Unsupported Media Type"
127+
status_code = UNSUPPORTED_MEDIA_TYPE
128+
severity = IssueSeverity.ERROR
129+
error_code = IssueCode.INVALID

gateway-api/src/gateway_api/get_structured_record/request.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
from gateway_api.common.error import (
1111
InvalidRequestJSONError,
1212
MissingOrEmptyHeaderError,
13+
UnsupportedMediaTypeError,
1314
)
1415

16+
ACCEPTED_CONTENT_TYPE = "application/fhir+json"
17+
1518
# Access record structured interaction ID from
1619
# https://developer.nhs.uk/apis/gpconnect/accessrecord_structured_development.html#spine-interactions
1720
ACCESS_RECORD_STRUCTURED_INTERACTION_ID = (
@@ -32,6 +35,7 @@ class GetStructuredRecordRequest:
3235
def __init__(self, request: Request) -> None:
3336
self._http_request = request
3437
self._headers = CaseInsensitiveDict(request.headers)
38+
self._validate_content_type()
3539
try:
3640
self.parameters = Parameters.model_validate(request.get_json())
3741
except (BadRequest, ValidationError) as error:
@@ -41,6 +45,13 @@ def __init__(self, request: Request) -> None:
4145

4246
self._validate_headers()
4347

48+
def _validate_content_type(self) -> None:
49+
content_type = self._headers.get("Content-Type")
50+
if content_type is None:
51+
return # if not provided, that's not invalid
52+
if content_type.split(";")[0].strip().lower() != ACCEPTED_CONTENT_TYPE:
53+
raise UnsupportedMediaTypeError()
54+
4455
@property
4556
def trace_id(self) -> str:
4657
trace_id: str = self._headers["Ssp-TraceID"]

gateway-api/tests/schema/test_openapi_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_api_schema_compliance(case: Case, base_url: str) -> None:
5353
# GPCAPIM-421
5454
schemathesis.checks.not_a_server_error,
5555
# GPCAPIM-419
56-
schemathesis.checks.missing_required_header,
56+
# schemathesis.checks.missing_required_header,
5757
# GPCAPIM-422
5858
schemathesis.checks.unsupported_method,
5959
],

schemathesis.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[generation]
22
mode = "all"
3+
4+
[checks.missing_required_header]
5+
expected-statuses = [400]

0 commit comments

Comments
 (0)