-
Notifications
You must be signed in to change notification settings - Fork 531
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
fix and test for issue 1758 #1760
Changes from 3 commits
707adcb
d70bfb5
ec4e0e4
ee37090
344f4e5
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 |
---|---|---|
|
@@ -958,6 +958,9 @@ public PathItem getPathItem(ObjectNode obj, String location, ParseResult result) | |
} else { | ||
pathItem.set$ref(ref.textValue()); | ||
} | ||
if(ref.textValue().startsWith("#/components") && !(ref.textValue().startsWith("#/components/pathItems"))) { | ||
result.warning(location, "$ref target "+ref.textValue() +" is not of expected type"); | ||
} | ||
if(result.isOpenapi31()){ | ||
String value = getString("summary", obj, false, location, result); | ||
if (StringUtils.isNotBlank(value)) { | ||
|
@@ -1535,6 +1538,9 @@ public Link getLink(ObjectNode linkNode, String location, ParseResult result) { | |
} else { | ||
link.set$ref(ref.textValue()); | ||
} | ||
if(ref.textValue().startsWith("#/components") && !(ref.textValue().startsWith("#/components/links"))) { | ||
result.warning(location, "$ref target "+ref.textValue() +" is not of expected type"); | ||
} | ||
if (result.isOpenapi31()) { | ||
String desc = getString("description", linkNode, false, location, result); | ||
if (StringUtils.isNotBlank(desc)) { | ||
|
@@ -1659,6 +1665,9 @@ public Callback getCallback(ObjectNode node, String location, ParseResult result | |
} else { | ||
callback.set$ref(ref.textValue()); | ||
} | ||
if(ref.textValue().startsWith("#/components") && !(ref.textValue().startsWith("#/components/callbacks"))) { | ||
result.warning(location, "$ref target "+ref.textValue() +" is not of expected type"); | ||
} | ||
return callback; | ||
} else { | ||
result.invalidType(location, "$ref", "string", node); | ||
|
@@ -1905,10 +1914,13 @@ public Parameter getParameter(ObjectNode obj, String location, ParseResult resul | |
parameter = new Parameter(); | ||
String mungedRef = mungedRef(ref.textValue()); | ||
if (mungedRef != null) { | ||
parameter.set$ref(mungedRef); | ||
} else { | ||
parameter.set$ref(ref.textValue()); | ||
} | ||
parameter.set$ref(mungedRef); | ||
}else { | ||
parameter.set$ref(ref.textValue()); | ||
} | ||
if(ref.textValue().startsWith("#/components") && !(ref.textValue().startsWith("#/components/parameters")||ref.textValue().startsWith("#/components/headers"))) { | ||
gracekarina marked this conversation as resolved.
Show resolved
Hide resolved
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. cdoe style, would replace |
||
result.warning(location, "$ref target "+ref.textValue() +" is not of expected type"); | ||
} | ||
if (result.isOpenapi31()) { | ||
String desc = getString("description", obj, false, location, result); | ||
if (StringUtils.isNotBlank(desc)) { | ||
|
@@ -2115,6 +2127,10 @@ public Header getHeader(ObjectNode headerNode, String location, ParseResult resu | |
} else { | ||
header.set$ref(ref.textValue()); | ||
} | ||
if(ref.textValue().startsWith("#/components") && !(ref.textValue().startsWith("#/components/parameters")||ref.textValue().startsWith("#/components/headers"))) { | ||
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. cdoe style, would replace |
||
result.warning(location, "$ref target "+ref.textValue() +" is not of expected type"); | ||
} | ||
|
||
if (result.isOpenapi31()) { | ||
String desc = getString("description", headerNode, false, location, result); | ||
if (StringUtils.isNotBlank(desc)) { | ||
|
@@ -2277,6 +2293,9 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR | |
} else { | ||
securityScheme.set$ref(ref.textValue()); | ||
} | ||
if(ref.textValue().startsWith("#/components") && !(ref.textValue().startsWith("#/components/securitySchemes"))) { | ||
result.warning(location, "$ref target "+ref.textValue() +" is not of expected type"); | ||
} | ||
if (result.isOpenapi31()) { | ||
String desc = getString("description", node, false, location, result); | ||
if (StringUtils.isNotBlank(desc)) { | ||
|
@@ -2698,6 +2717,9 @@ at the moment path passed as string (basePath) from upper components can be both | |
if(schema.get$ref().startsWith("#/components/schemas")){// it's internal | ||
String refName = schema.get$ref().substring(schema.get$ref().lastIndexOf("/")+1); | ||
localSchemaRefs.put(refName,location); | ||
} | ||
if(ref.textValue().startsWith("#/components") && !(ref.textValue().startsWith("#/components/schemas"))) { | ||
result.warning(location, "$ref target "+ref.textValue() +" is not of expected type"); | ||
} | ||
return schema; | ||
} else { | ||
|
@@ -3161,6 +3183,9 @@ public Example getExample(ObjectNode node, String location, ParseResult result) | |
} else { | ||
example.set$ref(ref.textValue()); | ||
} | ||
if(ref.textValue().startsWith("#/components") && !(ref.textValue().startsWith("#/components/examples"))) { | ||
result.warning(location, "$ref target "+ref.textValue() +" is not of expected type"); | ||
} | ||
if(result.isOpenapi31()){ | ||
String value = getString("summary", node, false, location, result); | ||
if (StringUtils.isNotBlank(value)) { | ||
|
@@ -3300,6 +3325,9 @@ public ApiResponse getResponse(ObjectNode node, String location, ParseResult res | |
} else { | ||
apiResponse.set$ref(ref.textValue()); | ||
} | ||
if(ref.textValue().startsWith("#/components") && !(ref.textValue().startsWith("#/components/responses"))) { | ||
result.warning(location, "$ref target "+ref.textValue() +" is not of expected type"); | ||
} | ||
if(result.isOpenapi31()){ | ||
String value = getString("description", node, false, location, result); | ||
if (StringUtils.isNotBlank(value)) { | ||
|
@@ -3550,6 +3578,9 @@ public RequestBody getRequestBody(ObjectNode node, String location, ParseResult | |
} else { | ||
body.set$ref(ref.textValue()); | ||
} | ||
if(ref.textValue().startsWith("#/components") && !(ref.textValue().startsWith("#/components/requestBodies"))) { | ||
result.warning(location, "$ref target "+ref.textValue() +" is not of expected type"); | ||
} | ||
if (result.isOpenapi31()) { | ||
String desc = getString("description", node, false, location, result); | ||
if (StringUtils.isNotBlank(desc)) { | ||
|
@@ -3806,6 +3837,9 @@ public Schema getJsonSchema(ObjectNode node, String location, ParseResult result | |
} else { | ||
schema.set$ref(ref.asText()); | ||
} | ||
if(ref.textValue().startsWith("#/components") && !(ref.textValue().startsWith("#/components/schemas"))) { | ||
result.warning(location, "$ref target "+ref.textValue() +" is not of expected type"); | ||
} | ||
} else { | ||
result.invalidType(location, "$ref", "string", node); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
openapi: 3.0.3 | ||
info: | ||
title: Missing validation rule for schemas in Headers. | ||
version: 1.0.0 | ||
servers: | ||
- url: / | ||
paths: | ||
/path1: | ||
$ref: '#/components/schemas/xFoo' | ||
/foo: | ||
get: | ||
description: ok | ||
parameters: | ||
- $ref: '#/components/schemas/xFoo' | ||
requestBody: | ||
$ref: '#/components/schemas/xFoo' | ||
responses: | ||
default: | ||
description: ok | ||
headers: | ||
three: | ||
$ref: '#/components/schemas/xFoo' | ||
'200': | ||
description: successful operation | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
$ref: '#/components/parameters/pet' | ||
examples: | ||
one: | ||
$ref: '#/components/schemas/xFoo' | ||
links: | ||
user: | ||
$ref: '#/components/schemas/xFoo' | ||
'400': | ||
$ref: '#/components/schemas/xFoo' | ||
callbacks: | ||
mainHook: | ||
$ref: "#/components/schemas/xFoo" | ||
components: | ||
schemas: | ||
xFoo: | ||
type: string | ||
description: This isn't validated correctly | ||
parameters: | ||
pet: | ||
name: X-pet | ||
in: header | ||
required: false | ||
schema: | ||
type: string | ||
format: uuid | ||
|
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.
I would detail what is the expected type, like
"$ref target "+ref.textValue() +" is not of expected type pathItem");
. Same applies to similar code below