Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [1.5.1-beta-1] - 2026-08-04

### Fixed
Expand All @@ -15,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- OAR082 - BinaryOrByteFormat - Issue message now shows the configured `fields-to-apply`.
- OAR085 - OpenAPIVersion - Issue message now shows the configured `valid-versions`.
- OAR037 - StringFormat - Issue message now interpolates the configured `formats-allowed`.
- OAR044 - MediaTypeCheck - Media type parameters now follow RFC 9110 (charset without space, other parameter names, multiple parameters); type/subtype can no longer start with `.`.


## [1.5.0] - 2026-07-28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,20 @@ public class OAR044MediaTypeCheck extends BaseCheck {
protected static final String MESSAGE_V3 = "OAR044.error.v3";
private final ExternalRefHandler handleExternalRef = new ExternalRefHandler();

private static final String RESTRICTED_NAME = "[a-zA-Z0-9][a-zA-Z0-9.!#$&^_+\\-]*";
private static final String OWS = "[ \\t]*";
private static final String TOKEN = "[a-zA-Z0-9!#$%&'*+\\-.^_`|~]+";
private static final String QUOTED_STRING = "\"(?:[^\"\\\\]|\\\\.)*\"";
private static final String PARAMETERS =
"(?:" + OWS + ";" + OWS + TOKEN + "=(?:" + TOKEN + "|" + QUOTED_STRING + "))*";

@VisibleForTesting
static final Pattern MIME_TYPE_PATTERN = Pattern.compile(
"[a-zA-Z0-9.][a-zA-Z0-9.!#$&_^+\\-]+/" +
"[a-zA-Z0-9.][a-zA-Z0-9.!#$&_^+\\-]+" +
"(; charset=[a-zA-Z0-9_\\-]+)?"
RESTRICTED_NAME + "/" + RESTRICTED_NAME + PARAMETERS
);
@VisibleForTesting
static final Pattern MEDIA_RANGE_PATTERN = Pattern.compile(
"(\\*|[a-zA-Z0-9.][a-zA-Z0-9.!#$&_^+\\-]+)/" +
"(\\*|" +
"[a-zA-Z0-9.][a-zA-Z0-9.!#$&_^+\\-]+" +
"(; charset=[a-zA-Z0-9_\\-]+)?" +
")"
"(\\*|" + RESTRICTED_NAME + ")/(\\*|" + RESTRICTED_NAME + ")" + PARAMETERS
);

@Override
Expand Down Expand Up @@ -114,8 +115,8 @@ private void verifyParameterContent(JsonNode node) {
for (JsonNode property : properties.values()) {
JsonNode keyNode = property.key();
String key = keyNode.getTokenValue();
if (!MIME_TYPE_PATTERN.matcher(key).matches()) {
addIssue(CHECK_KEY, translate(MESSAGE_V2), keyNode);
if (!MEDIA_RANGE_PATTERN.matcher(key).matches()) {
addIssue(CHECK_KEY, translate(MESSAGE_V3), keyNode);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/checks/v2/format/OAR044/media-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
}
},
"post" : {
"produces" : [ "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/ld+json", "text/csv", "image/png" ],
"consumes" : [ "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/ld+json" ],
"produces" : [ "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/ld+json", "text/csv", "image/png", "text/plain;charset=utf-8", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxk" ],
"consumes" : [ "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/ld+json", "application/json; charset=utf-8; boundary=xyz" ],
"responses" : {
"200" : {
"description" : "some operation"
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/checks/v2/format/OAR044/media-type.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ paths:
- application/ld+json
- text/csv
- image/png
- text/plain;charset=utf-8
- multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxk
consumes:
- application/vnd.ms-excel
- application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
- application/ld+json
- application/json; charset=utf-8; boundary=xyz
responses:
'200':
description: some operation
12 changes: 9 additions & 3 deletions src/test/resources/checks/v3/format/OAR044/media-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
"name" : "someParam",
"in" : "query",
"content" : {
"application" : { }, # Noncompliant {{OAR044: Declared mime type should conform to RFC6838}}
"application" : { }, # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
"text/*" : { },
"text/plain" : { }
}
},
},
{
"name" : "otherParam",
"in" : "path"
Expand All @@ -32,12 +33,17 @@
"requestBody" : {
"content" : {
"application" : { }, # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
".text/plain" : { }, # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
"text/*" : { },
"application/vnd.ms-excel" : { },
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : { },
"application/ld+json" : { },
"image/*" : { },
"*/*" : { }
"*/*" : { },
"text/plain;charset=utf-8" : { },
"multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxk" : { },
"multipart/form-data; boundary=\"----abc 123\"" : { },
"application/json; charset=utf-8; boundary=xyz" : { }
}
},
"responses" : {
Expand Down
8 changes: 7 additions & 1 deletion src/test/resources/checks/v3/format/OAR044/media-type.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@ paths:
- name: someParam
in: query
content:
'application': {} # Noncompliant {{OAR044: Declared mime type should conform to RFC6838}}
'application': {} # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
'text/*': {}
'text/plain': {} # invalid (only 1 content allowed by spec), but should not be caught by this rule
- name: otherParam
in: path
post:
requestBody:
content:
'application': { } # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
'.text/plain': { } # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
'text/*': { }
'application/vnd.ms-excel': {}
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': {}
'application/ld+json': {}
'image/*': {}
'*/*': {}
'text/plain;charset=utf-8': {}
'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxk': {}
'multipart/form-data; boundary="----abc 123"': {}
'application/json; charset=utf-8; boundary=xyz': {}
responses:
'200':
description: some operation
Expand Down
12 changes: 9 additions & 3 deletions src/test/resources/checks/v31/format/OAR044/media-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
"name" : "someParam",
"in" : "query",
"content" : {
"application" : { }, # Noncompliant {{OAR044: Declared mime type should conform to RFC6838}}
"application" : { }, # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
"text/*" : { },
"text/plain" : { }
}
},
},
{
"name" : "otherParam",
"in" : "path"
Expand All @@ -32,12 +33,17 @@
"requestBody" : {
"content" : {
"application" : { }, # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
".text/plain" : { }, # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
"text/*" : { },
"application/vnd.ms-excel" : { },
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : { },
"application/ld+json" : { },
"image/*" : { },
"*/*" : { }
"*/*" : { },
"text/plain;charset=utf-8" : { },
"multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxk" : { },
"multipart/form-data; boundary=\"----abc 123\"" : { },
"application/json; charset=utf-8; boundary=xyz" : { }
}
},
"responses" : {
Expand Down
8 changes: 7 additions & 1 deletion src/test/resources/checks/v31/format/OAR044/media-type.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@ paths:
- name: someParam
in: query
content:
'application': {} # Noncompliant {{OAR044: Declared mime type should conform to RFC6838}}
'application': {} # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
'text/*': {}
'text/plain': {} # invalid (only 1 content allowed by spec), but should not be caught by this rule
- name: otherParam
in: path
post:
requestBody:
content:
'application': { } # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
'.text/plain': { } # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
'text/*': { }
'application/vnd.ms-excel': {}
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': {}
'application/ld+json': {}
'image/*': {}
'*/*': {}
'text/plain;charset=utf-8': {}
'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxk': {}
'multipart/form-data; boundary="----abc 123"': {}
'application/json; charset=utf-8; boundary=xyz': {}
responses:
'200':
description: some operation
Expand Down
12 changes: 9 additions & 3 deletions src/test/resources/checks/v32/format/OAR044/media-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
"name" : "someParam",
"in" : "query",
"content" : {
"application" : { }, # Noncompliant {{OAR044: Declared mime type should conform to RFC6838}}
"application" : { }, # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
"text/*" : { },
"text/plain" : { }
}
},
},
{
"name" : "otherParam",
"in" : "path"
Expand All @@ -32,12 +33,17 @@
"requestBody" : {
"content" : {
"application" : { }, # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
".text/plain" : { }, # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
"text/*" : { },
"application/vnd.ms-excel" : { },
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : { },
"application/ld+json" : { },
"image/*" : { },
"*/*" : { }
"*/*" : { },
"text/plain;charset=utf-8" : { },
"multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxk" : { },
"multipart/form-data; boundary=\"----abc 123\"" : { },
"application/json; charset=utf-8; boundary=xyz" : { }
}
},
"responses" : {
Expand Down
8 changes: 7 additions & 1 deletion src/test/resources/checks/v32/format/OAR044/media-type.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@ paths:
- name: someParam
in: query
content:
'application': {} # Noncompliant {{OAR044: Declared mime type should conform to RFC6838}}
'application': {} # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
'text/*': {}
'text/plain': {} # invalid (only 1 content allowed by spec), but should not be caught by this rule
- name: otherParam
in: path
post:
requestBody:
content:
'application': { } # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
'.text/plain': { } # Noncompliant {{OAR044: Declared media type range should conform to RFC7231}}
'text/*': { }
'application/vnd.ms-excel': {}
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': {}
'application/ld+json': {}
'image/*': {}
'*/*': {}
'text/plain;charset=utf-8': {}
'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxk': {}
'multipart/form-data; boundary="----abc 123"': {}
'application/json; charset=utf-8; boundary=xyz': {}
responses:
'200':
description: some operation
Expand Down