Skip to content

Commit

Permalink
fix: update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ilfa committed Apr 25, 2023
1 parent 7c4fb3a commit 7dd69c4
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 47 deletions.
4 changes: 4 additions & 0 deletions docs/FingerprintApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,8 @@ null (empty response body)
- **Content-Type**: Not defined
- **Accept**: Not defined

### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **0** | Dummy for the schema | - |

65 changes: 23 additions & 42 deletions res/fingerprint-server-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3004,8 +3004,10 @@ paths:
schema:
$ref: '#/components/schemas/ErrorVisits403'
examples:
forbidden:
value: '{"error": "Forbidden (HTTP 403)"}'
example:
summary: Forbidden
value:
error: Forbidden (HTTP 403)
'429':
description: Too Many Requests
headers:
Expand All @@ -3021,12 +3023,11 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ManyRequestsResponse'
examples:
example:
summary: Example too many requests error response
value:
error:
message: too many requests
examples:
example:
summary: Example too many requests error response
value:
error: too many requests
/webhook:
trace:
tags:
Expand All @@ -3035,6 +3036,9 @@ paths:
Fake path to describe webhook format. More information about webhooks
can be found in the
[documentation](https://dev.fingerprint.com/docs/webhooks)
responses:
default:
description: Dummy for the schema
callbacks:
webhook:
webhook:
Expand All @@ -3047,7 +3051,6 @@ paths:
content:
application/json:
schema:
type: object
$ref: '#/components/schemas/WebhookVisit'
example:
value:
Expand Down Expand Up @@ -3099,6 +3102,9 @@ paths:
lastSeenAt:
global: '2022-03-16T11:28:34.023Z'
subscription: null
responses:
default:
description: The server doesn't validate the answer.
components:
securitySchemes:
ApiKeyHeader:
Expand Down Expand Up @@ -3174,14 +3180,8 @@ components:
type: boolean
firstSeenAt:
$ref: '#/components/schemas/SeenAt'
example:
global: '2022-05-05T18:28:54.535Z'
subscription: '2022-06-09T22:58:05.576Z'
lastSeenAt:
$ref: '#/components/schemas/SeenAt'
example:
global: '2022-06-09T22:58:35.795Z'
subscription: null
additionalProperties: false
required:
- browserDetails
Expand Down Expand Up @@ -3345,14 +3345,8 @@ components:
type: boolean
firstSeenAt:
$ref: '#/components/schemas/SeenAt'
example:
global: '2022-05-05T18:28:54.535Z'
subscription: '2022-06-09T22:58:05.576Z'
lastSeenAt:
$ref: '#/components/schemas/SeenAt'
example:
global: '2022-06-09T22:58:35.795Z'
subscription: null
additionalProperties: false
required:
- visitorId
Expand Down Expand Up @@ -3419,14 +3413,8 @@ components:
type: boolean
firstSeenAt:
$ref: '#/components/schemas/SeenAt'
example:
global: '2022-05-05T18:28:54.535Z'
subscription: '2022-06-09T22:58:05.576Z'
lastSeenAt:
$ref: '#/components/schemas/SeenAt'
example:
global: '2022-06-09T22:58:35.795Z'
subscription: null
required:
- browserDetails
- confidence
Expand Down Expand Up @@ -3502,14 +3490,19 @@ components:
type: string
nullable: true
format: date-time
example: '2022-05-05T18:28:54.535Z'
subscription:
type: string
nullable: true
format: date-time
example: '2022-06-09T22:58:05.576Z'
required:
- global
- subscription
title: SeenAt
example:
global: '2022-05-05T18:28:54.535Z'
subscription: null
IPLocation:
type: object
additionalProperties: false
Expand Down Expand Up @@ -3547,14 +3540,8 @@ components:
example: Prague
country:
$ref: '#/components/schemas/Location'
example:
code: US
name: United States
continent:
$ref: '#/components/schemas/Location'
example:
code: NA
name: North America
subdivisions:
type: array
items:
Expand Down Expand Up @@ -3598,7 +3585,7 @@ components:
description: >-
Contains all the information from each activated product - Fingerprint
Pro or Bot Detection
additionalProperties: false
additionalProperties: true
properties:
identification:
type: object
Expand Down Expand Up @@ -3663,14 +3650,8 @@ components:
type: boolean
firstSeenAt:
$ref: '#/components/schemas/SeenAt'
example:
global: '2022-05-05T18:28:54.535Z'
subscription: '2022-06-09T22:58:05.576Z'
lastSeenAt:
$ref: '#/components/schemas/SeenAt'
example:
global: '2022-06-09T22:58:35.795Z'
subscription: null
visitorId:
type: string
additionalProperties: false
Expand Down Expand Up @@ -3753,8 +3734,6 @@ components:
example: https://example.com/login
bot:
$ref: '#/components/schemas/BotdDetectionResult'
example:
result: notDetected
required:
- bot
- url
Expand All @@ -3776,6 +3755,8 @@ components:
- notDetected
- good
- bad
example:
result: notDetected
required:
- result
BotdError:
Expand Down
3 changes: 2 additions & 1 deletion scripts/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ curl -o ./res/fingerprint-server-api.yaml https://fingerprintjs.github.io/finger

examplesList=(
'visits_limit_500.json'
'get_event_extra_fields.json'
'get_event.json'
)

for example in ${examplesList[*]}; do
curl -o ./src/test/resources/mocks/"$example" https://fingerprintjs.github.io/fingerprint-pro-server-api-openapi/examples/"$example"
done

./scripts/generate.sh
./scripts/generate.sh
10 changes: 10 additions & 0 deletions src/main/java/com/fingerprint/api/FingerprintApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ public ApiResponse<Response> getVisitsWithHttpInfo(String visitorId, String requ
*
* Fake path to describe webhook format. More information about webhooks can be found in the [documentation](https://dev.fingerprint.com/docs/webhooks)
* @throws ApiException if fails to make API call
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 0 </td><td> Dummy for the schema </td><td> - </td></tr>
</table>
*/
public void webhookTrace() throws ApiException {
webhookTraceWithHttpInfo();
Expand All @@ -234,6 +239,11 @@ public void webhookTrace() throws ApiException {
* Fake path to describe webhook format. More information about webhooks can be found in the [documentation](https://dev.fingerprint.com/docs/webhooks)
* @return ApiResponse&lt;Void&gt;
* @throws ApiException if fails to make API call
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 0 </td><td> Dummy for the schema </td><td> - </td></tr>
</table>
*/
public ApiResponse<Void> webhookTraceWithHttpInfo() throws ApiException {
Object localVarPostBody = null;
Expand Down
47 changes: 45 additions & 2 deletions src/main/java/com/fingerprint/model/ProductsResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

package com.fingerprint.model;

import java.util.Map;
import java.util.HashMap;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import java.util.Objects;
import java.util.Arrays;
import java.util.Map;
Expand Down Expand Up @@ -100,6 +104,43 @@ public void setBotd(ProductsResponseBotd botd) {
this.botd = botd;
}

/**
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*/
private Map<String, Object> additionalProperties;

/**
* Set the additional (undeclared) property with the specified name and value.
* If the property does not already exist, create it otherwise replace it.
*/
@JsonAnySetter
public ProductsResponse putAdditionalProperty(String key, Object value) {
if (this.additionalProperties == null) {
this.additionalProperties = new HashMap<String, Object>();
}
this.additionalProperties.put(key, value);
return this;
}

/**
* Return the additional (undeclared) property.
*/
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}

/**
* Return the additional (undeclared) property with the specified name.
*/
public Object getAdditionalProperty(String key) {
if (this.additionalProperties == null) {
return null;
}
return this.additionalProperties.get(key);
}

/**
* Return true if this ProductsResponse object is equal to o.
Expand All @@ -114,12 +155,13 @@ public boolean equals(Object o) {
}
ProductsResponse productsResponse = (ProductsResponse) o;
return Objects.equals(this.identification, productsResponse.identification) &&
Objects.equals(this.botd, productsResponse.botd);
Objects.equals(this.botd, productsResponse.botd)&&
Objects.equals(this.additionalProperties, productsResponse.additionalProperties);
}

@Override
public int hashCode() {
return Objects.hash(identification, botd);
return Objects.hash(identification, botd, additionalProperties);
}

@Override
Expand All @@ -128,6 +170,7 @@ public String toString() {
sb.append("class ProductsResponse {\n");
sb.append(" identification: ").append(toIndentedString(identification)).append("\n");
sb.append(" botd: ").append(toIndentedString(botd)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/fingerprint/model/SeenAt.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public SeenAt global(OffsetDateTime global) {
* @return global
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
@ApiModelProperty(example = "2022-05-05T18:28:54.535Z", required = true, value = "")
@JsonProperty(JSON_PROPERTY_GLOBAL)
@JsonInclude(value = JsonInclude.Include.ALWAYS)

Expand All @@ -83,7 +83,7 @@ public SeenAt subscription(OffsetDateTime subscription) {
* @return subscription
**/
@javax.annotation.Nullable
@ApiModelProperty(required = true, value = "")
@ApiModelProperty(example = "2022-06-09T22:58:05.576Z", required = true, value = "")
@JsonProperty(JSON_PROPERTY_SUBSCRIPTION)
@JsonInclude(value = JsonInclude.Include.ALWAYS)

Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/fingerprint/api/FingerprintApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class FingerprintApiTest {
private FingerprintApi api;
private final String MOCK_REQUEST_ID = "0KSh65EnVoB85JBmloQK";
private final String MOCK_REQUEST_WITH_EXTRA_FIELDS_ID = "EXTRA_FIELDS";
private final String MOCK_VISITOR_ID = "AcxioeQKffpXF8iGQK3P";
private final String MOCK_VISITOR_REQUEST_ID = "1655373780901.HhjRFX";

Expand All @@ -44,6 +45,7 @@ private InputStream getFileAsIOStream(final String fileName) {
public void before() throws ApiException, IOException {
api = Mockito.mock(FingerprintApi.class);
when(api.getEvent(MOCK_REQUEST_ID)).thenReturn(fetchMockEvent());
when(api.getEvent(MOCK_REQUEST_WITH_EXTRA_FIELDS_ID)).thenReturn(fetchMockWithExtraFieldsEvent());
when(api.getVisits(MOCK_VISITOR_ID, MOCK_VISITOR_REQUEST_ID, null, 50, 0L)).thenReturn(fetchMockVisit());
}

Expand All @@ -53,6 +55,12 @@ private EventResponse fetchMockEvent() throws IOException {
return mapper.readValue(getFileAsIOStream("mocks/get_event.json"), EventResponse.class);
}

private EventResponse fetchMockWithExtraFieldsEvent() throws IOException {
ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());

return mapper.readValue(getFileAsIOStream("mocks/get_event_extra_fields.json"), EventResponse.class);
}

private Response fetchMockVisit() throws IOException {
ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());

Expand All @@ -74,6 +82,22 @@ public void getEventTest() throws ApiException {
assertEquals(response.getProducts().getIdentification().getData().getVisitorId(), "Ibk1527CUFmcnjLwIs4A9");
}

/**
* Get event by requestId
* This endpoint allows you to get events with all the information from each activated product (Fingerprint Pro or Bot Detection). Use the requestId as a URL path :request_id parameter. This API method is scoped to a request, i.e. all returned information is by requestId.
* Answer will contain fields of additional products that don't described in schema
*
* @throws ApiException if the Api call fails
*/
@Test
public void getEventWithExtraFieldsTest() throws ApiException {
EventResponse response = api.getEvent(MOCK_REQUEST_WITH_EXTRA_FIELDS_ID);
assert response.getProducts() != null;
assert response.getProducts().getIdentification() != null;
assert response.getProducts().getIdentification().getData() != null;
assertEquals(response.getProducts().getIdentification().getData().getVisitorId(), "Ibk1527CUFmcnjLwIs4A9");
}

/**
* Get visits by visitorId
* This endpoint allows you to get a history of visits with all available information. Use the visitorId as a URL path parameter. This API method is scoped to a visitor, i.e. all returned information is by visitorId.
Expand Down
Loading

0 comments on commit 7dd69c4

Please sign in to comment.