Add a test case for inline models within Callback Object (#3665)

This commit is contained in:
Akihito Nakano 2019-08-19 23:52:06 +09:00 committed by William Cheng
parent 8c498fb08a
commit 6addd76e11
2 changed files with 72 additions and 0 deletions

View File

@ -804,4 +804,42 @@ public class InlineModelResolverTest {
Schema nullableRequestBodySchema = ModelUtils.getReferencedSchema(openAPI, nullableRequestBodyReference);
assertTrue(nullableRequestBodySchema.getNullable());
}
@Test
public void callbacks() {
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
new InlineModelResolver().flatten(openAPI);
RequestBody callbackRequestBodyReference = openAPI
.getPaths()
.get("/callback")
.getPost()
.getCallbacks()
.get("webhook")
.get("{$request.body#/callbackUri}")
.getPost()
.getRequestBody();
assertNotNull(callbackRequestBodyReference.get$ref());
RequestBody resolvedCallbackRequestBody = openAPI
.getComponents()
.getRequestBodies()
.get(ModelUtils.getSimpleRef(callbackRequestBodyReference.get$ref()));
Schema callbackRequestSchemaReference = resolvedCallbackRequestBody
.getContent()
.get("application/json")
.getSchema();
assertNotNull(callbackRequestSchemaReference.get$ref());
Schema resolvedCallbackSchema = openAPI
.getComponents()
.getSchemas()
.get(ModelUtils.getSimpleRef(callbackRequestSchemaReference.get$ref()));
Map properties = resolvedCallbackSchema.getProperties();
assertTrue(properties.get("notificationId") instanceof StringSchema);
assertTrue(properties.get("action") instanceof StringSchema);
assertTrue(properties.get("data") instanceof StringSchema);
}
}

View File

@ -293,6 +293,40 @@ paths:
responses:
'200':
description: OK
/callback:
post:
requestBody:
content:
application/json:
schema:
type: object
properties:
callbackUri:
type: string
responses:
201:
headers:
Location:
description: Contains the URI of the newly created resource
schema:
type: string
callbacks:
webhook:
'{$request.body#/callbackUri}':
post:
operationId: webhookNotify
requestBody:
content:
application/json:
schema:
type: object
properties:
notificationId:
type: string
action:
type: string
data:
type: string
components:
schemas:
Users: