Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ public void runObjectValidations() {
checkRequired(parameter);
validateStringField(F_style, false, Regexes.STYLE_REGEX);
checkAllowReserved(parameter);
// TODO Q: Should schema be required in parameter object?
validateField(F_schema, false, Schema.class, new SchemaValidator());
validateMapField(F_contentMediaTypes, false, false, MediaType.class, new MediaTypeValidator());
Overlay<?> schemaOverlay = validateField(F_schema, false, Schema.class, new SchemaValidator());
Overlay<?> contentOverlay = validateMapField(F_contentMediaTypes, false, false, MediaType.class,
new MediaTypeValidator());
// Schema xor content must be present
checkSchemaContentXor(schemaOverlay,contentOverlay);
validateExtensions(parameter.getExtensions());
}

Expand Down Expand Up @@ -98,7 +100,20 @@ void checkExampleExclusion(Overlay<Map<String, Example>> examples, Overlay<Objec
&& Overlay.getMapOverlay(examples).size() > 0;
boolean examplePresent = example != null && example.isPresent();
if (examplesPresent && examplePresent) {
results.addError("ExmplExclusion|The 'example' and 'exmaples' properties may not both appear", value);
results.addError("ExmplExclusion|The 'example' and 'examples' properties may not both appear", value);
}
}

private void checkSchemaContentXor(Overlay<?> schemaOverlay, Overlay<?> contentOverlay) {
int count = 0;
if (schemaOverlay != null && schemaOverlay.isPresent()) {
count++;
}
if (contentOverlay != null && contentOverlay.isPresent()) {
count++;
}
if (count != 1) {
results.addError("Exactly one of schema|content must be present", value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public void shouldPass_OnValidParam() throws Exception {
assertTrue(model.isValid());
}

@Test
public void shouldFail_OnInValidParamType() throws Exception {
OpenApi3 model = new OpenApi3Parser().parse(getClass().getResource("/models/params/invalidParamType.yaml"), true);

assertEquals(1, model.getValidationItems().size());
assertEquals("Exactly one of schema|content must be present", model.getValidationItems().iterator().next().getMsg() );
assertFalse(model.isValid());
}

@Test
public void shouldAllow_HybridPathParam() throws Exception {
OpenApi3 model = new OpenApi3Parser().parse(getClass().getResource("/models/params/hybridParam.yaml"), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ paths:
- in: path
name: params
required: true
schema:
type: string
responses:
200:
description: Ok
description: Ok
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ paths:
- in: path
name: id
required: true
schema:
type: string
responses:
200:
description: Ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
openapi: "3.0.0"
info:
version: 1.0.0
title: My API Spec
paths:
/{id}:
get:
parameters:
- in: path
name: id
required: true
schema:
type: string
content:
application/json:
schema:
type: string
responses:
200:
description: Ok
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ paths:
- in: path
name: customerID
required: true
schema:
type: string
- in: path
name: orderID
required: true
schema:
type: integer
responses:
200:
description: Ok
description: Ok
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ paths:
parameters:
- in: path
name: id
schema:
type: string
responses:
200:
description: Ok
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ paths:
- in: path
name: id
required: true
schema:
type: string
responses:
200:
description: Ok