Remove the certain properties of objects from the json document response Swagger for REST api - swagger

Hi I am using swagger for documentation of my RESTful web service. wanted to know is there any way to remove the certain properties of objects from the json document response? I mean there are lots of properties that swagger gives for my method param objects and response model (e.g. notes, defaultValue, allowableValue, internalDescription etc.) that are not required for me and are null due to that the response is not much readable
For method params:
"parameters": [
{
"name": "someName1",
"description": null,
"notes": null,
"paramType": "path",
"defaultValue": null,
"allowableValues": null,
"required": true,
"allowMultiple": false,
"paramAccess": null,
"internalDescription": null,
"wrapperName": null,
"dataType": "string",
"valueTypeInternal": null
},
{
"name": "someName2",
"description": null,
"notes": null,
"paramType": "query",
"defaultValue": null,
"allowableValues": null,
"required": true,
"allowMultiple": false,
"paramAccess": null,
"internalDescription": null,
"wrapperName": null,
"dataType": "string",
"valueTypeInternal": null
}
],
-=============================================================================
For response model classes
"SomeResponseClass": {
"required": false,
"name": null,
"id": "SomeResponseClass",
"properties": {
"instanceVariable1": {
"required": false,
"name": null,
"id": null,
"properties": null,
"allowableValues": null,
"description": null,
"notes": null,
"access": null,
"default": null,
"additionalProperties": null,
"items": null,
"uniqueItems": false,
"type": "Date"
},
"instanceVariable2": {
"required": false,
"name": null,
"id": null,
"properties": null,
"allowableValues": null,
"description": null,
"notes": null,
"access": null,
"default": null,
"additionalProperties": null,
"items": null,
"uniqueItems": false,
"type": "double"
}
}

your JSON mapper is not configured to ignore null properties. You can easily address this as follows:
#Provider
#Produces(MediaType.APPLICATION_JSON)
public class JacksonJsonProvider extends JacksonJaxbJsonProvider {
private static ObjectMapper commonMapper = null;
public JacksonJsonProvider() {
if(commonMapper == null){
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
commonMapper = mapper;
}
super.setMapper(commonMapper);
}
}
Add this mapper to your scanning properties in the web.xml and the nulls will be gone.

Related

Retrieve homePhone, mobilePhone and faxPhone from Delve Profile using Graph API

I am trying to retrieve the information in the red box via the graph api resource:
https://graph.microsoft.com/beta/me/profile
Here is the return:
"phones": [
{
"displayName": null,
"type": "business",
"number": "xxxxxxxxxx",
"allowedAudiences": "organization",
"createdDateTime": "2021-06-21T23:36:38.0912984Z",
"inference": null,
"lastModifiedDateTime": "2021-06-21T23:36:38.0912984Z",
"id": "a28e87ba-25xx-45xx-8fxx-5f340b597fxx",
"isSearchable": false,
"createdBy": {
"device": null,
"user": null,
"application": {
"displayName": "AAD",
"id": null
}
},
"lastModifiedBy": {
"device": null,
"user": null,
"application": {
"displayName": "AAD",
"id": null
}
},
"source": {
"type": [
"AAD"
]
}
}
],
It looks to only be returning the info from AAD, not the fields in the Delve profile. Upon further research I found these fields are actually linked to the SharePoint online profile. Is there a way to grab this information using the Graph API?

MS Teams Graph API: Get all teams user(s) are apart of

I want to use the graph api to get the teams a list of users is a member/owner of. I am using this endpoint to pass the list of users, then select the properties of the group that I am interested in:
/beta/users/$filter=id+in+('user-1','user-2','user-15')$expand=transitiveMemberOf($select=id,resourceProvisioningOptions,displayName,mailNickname)&$select=id,resourceProvisioningOptions,displayName
This will return a list of groups the member is apart of, including the Teams the member is apart of (up to 15 users). It will filter the groups to only return id,resourceProvisioningOption,displayName and mailNickname.
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,resourceProvisioningOptions,displayName,transitiveMemberOf(id,resourceProvisioningOptions,displayName,mailNickname))",
"value": [
{
"id": "user-1",
"displayName": "Jeff Smith",
"transitiveMemberOf": [
{
"#odata.type": "#microsoft.graph.directoryRole",
"id": "directoryRole-1",
"displayName": null
},
{
"#odata.type": "#microsoft.graph.directoryRole",
"id": "directoryRole-2",
"displayName": null
},
{
"#odata.type": "#microsoft.graph.group",
"id": "team-id-1",
"resourceProvisioningOptions": [
"Team"
],
"displayName": "My Team 1",
"mailNickname": "MyTeam1"
},
{
"#odata.type": "#microsoft.graph.directoryRole",
"id": "directoryRole-3",
"displayName": null
},
{
"#odata.type": "#microsoft.graph.group",
"id": "team-id-2",
"resourceProvisioningOptions": [
"Team"
],
"displayName": "My Team 2",
"mailNickname": "MyTeam2"
}
]
}
]
}
Since the user is apart of Azure directory groups, those are returned, but the resourceProvisioningOptions identifies if the user is on a team. In this case - 2 teams.
Problem
When looking in the Teams App, we see that the user is actually apart of the 10 different teams.
When calling this endpoint: https://graph.microsoft.com/v1.0/users/user-1/joinedTeams we see that the user is apart of 10 teams
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#teams",
"#odata.count": 10,
"value": [
{
"id": "team-id-1",
"createdDateTime": null,
"displayName": "Team 1",
"description": "Team1",
"internalId": null,
"classification": null,
"specialization": null,
"visibility": null,
"webUrl": null,
"isArchived": false,
"isMembershipLimitedToOwners": null,
"memberSettings": null,
"guestSettings": null,
"messagingSettings": null,
"funSettings": null,
"discoverySettings": null,
"summary": null
},
{
"id": "team-id-2",
"createdDateTime": null,
"displayName": "Team 2",
"description": "Team2",
"internalId": null,
"classification": null,
"specialization": null,
"visibility": null,
"webUrl": null,
"isArchived": false,
"isMembershipLimitedToOwners": null,
"memberSettings": null,
"guestSettings": null,
"messagingSettings": null,
"funSettings": null,
"discoverySettings": null,
"summary": null
},
...
{
"id": "team-id-10",
"createdDateTime": null,
"displayName": "Team 3",
"description": "Team3",
"internalId": null,
"classification": null,
"specialization": null,
"visibility": null,
"webUrl": null,
"isArchived": false,
"isMembershipLimitedToOwners": null,
"memberSettings": null,
"guestSettings": null,
"messagingSettings": null,
"funSettings": null,
"discoverySettings": null,
"summary": null
}
]
}
Questions:
Is there another endpoint that I can use to pass a list of users and get the teams they are owner/member of?
Why is the data different between endpoints
I am trying to avoid calling the /joinedTeams endpoint due to number of users and rate limiting.
You could use the /joinedTeams endpoint, but also put those calls in a batch to MS Graph.
See: https://learn.microsoft.com/en-us/graph/json-batching
This would allow you to send a batch of 20 (i think) requests in one call to the graph making it much faster and less likely to be throttled.

How to bypass errors and parse json field values

How to deserialize below JSON?
When i am using below code
Response response=engine.getResponse(Method.GET,strURL,strBAUsername,strBAPassword,null,ContentType.JSON);
userEdit=response.as(TestUserRoleInfoList.class); // TestUserRoleInfoList is a POJO class
#JsonIgnoreProperties(ignoreUnknown=true)
public class TestUserRoleInfoList {
#JsonProperty("userRoleInfoList")
List<UserRoleInfo> userRoleInfo=new ArrayList<UserRoleInfo>();
public List<UserRoleInfo> getUserRoleInfo() {
return userRoleInfo;
}
public void setUserRoleInfo(List<UserRoleInfo> userRoleInfo) {
this.userRoleInfo = userRoleInfo;
}
}
Somehow it unable to parse Regions internal class. But i am least bothered. I need collectionRole fields.
How can i get the list of collection roles?
{
"id": 5595,
"userName": "abc",
"firstName": "abc",
"lastName": "ijk",
"additionalName": "Ernest",
"namePrefix": {
"id": null,
"prefix": null,
"createdAt": null,
"updatedAt": null
},
"nameSuffix": {
"id": null,
"suffix": null,
"createdAt": null,
"updatedAt": null
},
"emplId": "11111",
"workDayId": "11111",
"staffEmailAddress": null,
"facultyEmailAddress": "abc.xyz#xxxx.edu",
"userRoleInfoList": [
{
"userId": 5595,
"collectionRole": "program-chair",
"regions": [
{
"id": 1,
"region": "Germany 1",
"regionalDirectorFirstName": "aaaa",
"regionalDirectorLastName": "bbbb",
"associateDirectorFirstName": null,
"associateDirectorLastName": null,
"division": {
"id": 2,
"name": "Europe",
"deletedFlag": false,
"createdAt": null,
"updatedAt": null
},
"deletedFlag": false,
"createdAt": null,
"updatedAt": null
}
],
"school": {
"id": 3,
"name": "Arts and Sciences",
"dean": null,
"createdAt": null,
"updatedAt": null
},
"facultyPhoto": null,
"primary": false
},
{
"userId": 5595,
"collectionRole": "faculty",
"regions": [
{
"id": 3,
"region": "Germany 1",
"regionalDirectorFirstName": "aaaa",
"regionalDirectorLastName": "bbbb",
"associateDirectorFirstName": null,
"associateDirectorLastName": null,
"division": {
"id": 2,
"name": "Europe",
"deletedFlag": false,
"createdAt": null,
"updatedAt": null
},
"deletedFlag": false,
"createdAt": null,
"updatedAt": null
}
],
"school": {
"id": 3,
"name": "Arts and Sciences",
"dean": null,
"createdAt": null,
"updatedAt": null
},
"facultyPhoto": null,
"primary": true
}
]
}
You can use org.json.JSONObject
Response response = when()
.get("api_url")
.then()
.extract().response();
JSONObject jsonObject = new JSONObject(response.getBody().asString());
JSONArray jsonArray = jsonObject.getJSONArray("userRoleInfoList");
List<String> stringList = new ArrayList<>();
for (int i = 0; i < jsonArray.length(); i++) {
stringList.add(jsonArray.getJSONObject(i).getString("collectionRole"));
}
System.out.println(stringList);
This will output [program-chair, faculty]

Why a member cannot receive messages from others in a group call chat of Teams

I used Create Call of Microsoft Graph API to create a group call(audio). The connection has created successfully, but every member cannot receive any chat message posted by other members.
(picture)The phenomenon that everyone cannot receive other's message
Request as below:
POST https://graph.microsoft.com/beta/app/calls
Content-Type: application/json
Authorization: Bearer <Token>
{
"#odata.type": "#microsoft.graph.call",
"callbackUri": "https://myhostname.ngrok.io/callback/calling",
"mediaConfig": {
"#odata.type": "#microsoft.graph.serviceHostedMediaConfig"
},
"source": {
"identity": {
"application": {
"id": "myCallingAppId"
}
}
},
"subject": "Test Call",
"targets": [
{
"identity": {
"user": {
"id": "User_1-Id",
"displayName": "User_1-DisplayName"
}
},
"identity": {
"user": {
"id": "User_2-Id",
"displayName": "User_2-Name"
}
}
}
],
"tenantId": "myCallingAppTenant"
}
Response:
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#communications/calls/$entity",
"id": "481f0c00-ffff-41cd-bbc8-7e21fb5e8b1b",
"state": "establishing",
"transferState": null,
"terminationReason": null,
"direction": "outgoing",
"ringingTimeoutInSeconds": null,
"subject": "Test Call",
"callbackUri": "https://myhostname.ngrok.io/callback/calling",
"requestedModalities": [],
"activeModalities": [],
"routingPolicies": [],
"tenantId": "myCallingAppTenant",
"myParticipantId": "59e11e38-87d0-4ae5-b3ce-051ea26aa34d",
"mediaState": null,
"resultInfo": null,
"answeredBy": null,
"chatInfo": null,
"meetingInfo": null,
"meetingCapability": null,
"toneInfo": null,
"incomingContext": null,
"callRoutes": [],
"source": {
"region": null,
"languageId": null,
"identity": {
"user": null,
"device": null,
"phone": null,
"application": {
"id": "myCallingAppId",
"displayName": null
}
}
},
"targets": [
{
"region": null,
"languageId": null,
"identity": {
"application": null,
"device": null,
"phone": null,
"user": {
"id": "User_1-Id",
"displayName": "User_1-DisplayName"
}
}
},
{
"region": null,
"languageId": null,
"identity": {
"application": null,
"device": null,
"phone": null,
"user": {
"id": "User_2-Id",
"displayName": "User_2-DisplayName"
}
}
}
],
"mediaConfig": {
"#odata.type": "#microsoft.graph.serviceHostedMediaConfig",
"removeFromDefaultAudioGroup": null,
"preFetchMedia": []
}
}
Is any configuration missed. How to create a calling with normal message communication. Could anyone help me, thanks!

Filter contacts in outlook API using startswith()

I am trying to get a list of contacts that are filtered by email address from Microsoft Outlook API (Contact API). The url I am using for the request is:
https://outlook.office.com/api/v2.0/me/contacts/?$filter=EmailAddresses/any(email: startswith(email/Address,'ab'))
The filter property $filter=EmailAddresses/any(email: email/Address eq 'ab') is working fine.
Here EmailAddresses field is a list containing name, address fields.
UPDATE
Original response :
{
"#odata.context": "https://outlook.office.com/api/v2.0/$metadata#Me/Contacts",
"value": [
{
..................................
..................................
"DisplayName": "Abhishek R",
"GivenName": "Abhishek",
"Initials": null,
"MiddleName": null,
"NickName": null,
"Surname": "R",
"Title": null,
"YomiGivenName": null,
"YomiSurname": null,
"YomiCompanyName": null,
"Generation": null,
"ImAddresses": [],
"JobTitle": null,
"CompanyName": null,
"Department": null,
"OfficeLocation": null,
"Profession": null,
"BusinessHomePage": null,
"AssistantName": null,
"Manager": null,
"HomePhones": [],
"MobilePhone1": null,
"BusinessPhones": [],
"SpouseName": null,
"PersonalNotes": null,
"Children": [],
"EmailAddresses": [
{
"Name": "abhishek#gmail.com",
"Address": "abhishek#gmail.com"
},
{
"Name": "abcdef#gmail.com",
"Address": "abcdef#gmail.com"
}
],
"HomeAddress": {},
"BusinessAddress": {},
"OtherAddress": {}
}
]
}
The response I got is:
{
"error": {
"code": "ErrorInvalidUrlQueryFilter",
"message": "The query filter contains one or more invalid nodes."
}
}
Looking for a solution to this.

Resources