use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class BeanParamTest method shouldSerializeTypeParameter.
// tests issue #2466
@Test(description = "check array type of serialized BeanParam containing QueryParams")
public void shouldSerializeTypeParameter() {
OpenAPI openApi = new Reader(new OpenAPI()).read(MyBeanParamResource.class);
List<Parameter> getOperationParams = openApi.getPaths().get("/").getGet().getParameters();
Assert.assertEquals(getOperationParams.size(), 1);
Parameter param = getOperationParams.get(0);
Assert.assertEquals(param.getName(), "listOfStrings");
Schema<?> schema = param.getSchema();
// These are the important checks:
Assert.assertEquals(schema.getClass(), ArraySchema.class);
Assert.assertEquals(((ArraySchema) schema).getItems().getType(), "string");
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testLinkWithRef.
@Test(description = "Link with Ref")
public void testLinkWithRef() {
Components components = new Components();
components.addLinks("Link", new Link().description("Link Description").operationId("id"));
OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(RefLinksResource.class);
String yaml = "openapi: 3.0.1\n" + "info:\n" + " description: info\n" + "paths:\n" + " /links:\n" + " get:\n" + " operationId: getUserWithAddress\n" + " parameters:\n" + " - name: userId\n" + " in: query\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: test description\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/User'\n" + " links:\n" + " address:\n" + " operationId: getAddress\n" + " parameters:\n" + " userId: $request.query.userId\n" + " $ref: '#/components/links/Link'\n" + "components:\n" + " links:\n" + " Link:\n" + " operationId: id\n" + " description: Link Description\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method test2818.
@Test(description = "test ticket #2818 @Parameter annotation")
public void test2818() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(Ticket2818Resource.class);
Paths paths = openAPI.getPaths();
assertEquals(paths.size(), 1);
PathItem pathItem = paths.get("/bookstore/{id}");
assertNotNull(pathItem);
Operation operation = pathItem.getGet();
assertNotNull(operation);
assertEquals(operation.getParameters().get(0).getSchema().getType(), "integer");
assertEquals(operation.getParameters().get(0).getSchema().getFormat(), "int32");
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testSchemaProperties.
@Test(description = "Test SchemaProperties and additionalProperties annotations")
public void testSchemaProperties() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(SchemaPropertiesResource.class);
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /:\n" + " get:\n" + " summary: Simple get operation\n" + " description: Defines a simple get operation with no inputs and a complex output\n" + " object\n" + " operationId: getWithPayloadResponse\n" + " responses:\n" + " \"200\":\n" + " description: voila!\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: object\n" + " properties:\n" + " foo:\n" + " maximum: 1\n" + " type: integer\n" + " default:\n" + " description: boo\n" + " content:\n" + " application/json:\n" + " schema:\n" + " maxProperties: 3\n" + " type: object\n" + " properties:\n" + " foo:\n" + " maximum: 1\n" + " type: integer\n" + " description: various properties\n" + " \"400\":\n" + " description: additionalProperties schema\n" + " content:\n" + " application/json:\n" + " schema:\n" + " maxProperties: 2\n" + " type: object\n" + " additionalProperties:\n" + " type: string\n" + " \"401\":\n" + " description: additionalProperties boolean\n" + " content:\n" + " application/json:\n" + " schema:\n" + " maxProperties: 2\n" + " type: object\n" + " additionalProperties: false\n" + " deprecated: true\n" + " /one:\n" + " get:\n" + " operationId: requestBodySchemaPropertyNoSchema\n" + " requestBody:\n" + " content:\n" + " application/yaml:\n" + " schema:\n" + " type: object\n" + " properties:\n" + " foo:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/MultipleBaseBean'\n" + " /two:\n" + " get:\n" + " operationId: requestBodySchemaPropertySchema\n" + " requestBody:\n" + " content:\n" + " application/yaml:\n" + " schema:\n" + " required:\n" + " - foo\n" + " type: object\n" + " properties:\n" + " foo:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/MultipleBaseBean'\n" + " /three:\n" + " get:\n" + " operationId: requestBodySchemaPropertySchemaArray\n" + " requestBody:\n" + " content:\n" + " application/yaml:\n" + " schema:\n" + " type: array\n" + " items:\n" + " required:\n" + " - foo\n" + " type: object\n" + " properties:\n" + " foo:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/MultipleBaseBean'\n" + "components:\n" + " schemas:\n" + " MultipleBaseBean:\n" + " type: object\n" + " properties:\n" + " beanType:\n" + " type: string\n" + " a:\n" + " type: integer\n" + " format: int32\n" + " b:\n" + " type: string\n" + " description: MultipleBaseBean\n" + " MultipleSub1Bean:\n" + " type: object\n" + " description: MultipleSub1Bean\n" + " allOf:\n" + " - $ref: '#/components/schemas/MultipleBaseBean'\n" + " - type: object\n" + " properties:\n" + " c:\n" + " type: integer\n" + " format: int32\n" + " MultipleSub2Bean:\n" + " type: object\n" + " description: MultipleSub2Bean\n" + " allOf:\n" + " - $ref: '#/components/schemas/MultipleBaseBean'\n" + " - type: object\n" + " properties:\n" + " d:\n" + " type: integer\n" + " format: int32\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testGetCallbacks.
@Test(description = "Callbacks")
public void testGetCallbacks() {
Reader reader = new Reader(new OpenAPI());
Method[] methods = SimpleCallbackResource.class.getMethods();
Operation callbackOperation = reader.parseMethod(methods[0], null, null);
assertNotNull(callbackOperation);
Map<String, Callback> callbacks = callbackOperation.getCallbacks();
assertNotNull(callbacks);
Callback callback = callbacks.get(CALLBACK_SUBSCRIPTION_ID);
assertNotNull(callback);
PathItem pathItem = callback.get(CALLBACK_URL);
assertNotNull(pathItem);
Operation postOperation = pathItem.getPost();
assertNotNull(postOperation);
assertEquals(CALLBACK_POST_OPERATION_DESCRIPTION, postOperation.getDescription());
Operation getOperation = pathItem.getGet();
assertNotNull(getOperation);
assertEquals(CALLBACK_GET_OPERATION_DESCRIPTION, getOperation.getDescription());
Operation putOperation = pathItem.getPut();
assertNotNull(putOperation);
assertEquals(CALLBACK_POST_OPERATION_DESCRIPTION, putOperation.getDescription());
}
Aggregations