Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APOLLO-24186 Removed schema and Get mentions #71

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
76 changes: 5 additions & 71 deletions java-sdk/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ To build a valid connector configuration, you must:
* Apply a few annotations.
* Define connector "getter" methods and annotations.

All methods that are annotated with `@Property` and start with "get" are considered to be configuration properties.
For example, `@Property() String getName();` results in a String property called `name`.
All methods that are annotated with `@Property` and are considered to be configuration properties.
For example, `@Property() String name();` results in a String property called `name`.
This property would then be present in the generated schema.

Here is an example of the most basic configuration, along with required annotations and a sample "getter" method:
Here is an example of the most basic configuration, along with required annotations and a sample property access methods:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Here is an example of the most basic configuration, along with required annotations and a sample property access methods:
Here is an example of the most basic configuration, along with required annotations and sample property access methods:


```java
@RootSchema(
Expand All @@ -26,7 +26,7 @@ public interface MyConfig extends ConnectorConfig<MyConfig.Properties> {
title = "Properties",
required = true
)
public Properties getProperties();
public Properties properties();

/**
* Connector specific settings
Expand All @@ -37,7 +37,7 @@ public interface MyConfig extends ConnectorConfig<MyConfig.Properties> {
title = "My custom property",
description = "My custom property description"
)
public Integer getMyCustomProperty();
public Integer myCustomProperty();

}

Expand All @@ -53,69 +53,3 @@ Once a connector configuration has been defined, it can be associated with the `
From that point, the framework takes care of providing the configuration instances to your connector.
It also generates the schema, and sends it along to Fusion when it connects to Fusion.

=== About com.lucidworks.schema
The `com.lucidworks.schema` project (included in the connectors SDK) aims to simplify the process of creating JSON Schemas.
It also provides utilities for building type-safe POJOs from schema definitions.

The basic idea here is that you create an interface that extends `Model`, add property getters, and then add a few annotations.
Once your interface has been built, you can generate an `ObjectType` instance, which is the object that contains all of the JSON schema metadata.
By then combining that schema object with a `Map<String,Object>`, you can create instances of your interface to use as configuration objects.

The configuration objects are based on `java.lang.reflect.Proxy`, which is what the `ModelGenerator` returns.
Most method calls to these proxy instances result in method calls to the underlying `Map<String,Object>`.
For example, if the interface defines a `getId` method, then a runtime call results in a call to the `Map<String,Object>`: `data.get("id")`.

A few special cases exist:

* `toString` is proxied directly to the `Map<String,Object>`
* `getClass` returns the class of the interface provided to `ModelGenerator#generate()`
* `_data` returns the underlying `Map<String,Object>` object
* If the method starts with `set`, the arguments are captured and sent to the underlying map via `put()`

Here is a simple example:

```java
interface MyConfig extends Model {

@Property
@StringSchema(minLength=1)
String getId();

}
```

Create the schema:

```java
class Runner {
public static void main(String[] args){
ObjectType schema = SchemaGenerator.generate(MyConfig.class);
}
}
```

Generate an instance of the `MyConfig` class:

```java
class Runner {
public static void main(String[] args){
Map<String,Object> data = new java.util.HashMap<>();
data.put("id", 100);
MyConfig config = ModelGenerator.generate(MyConfig.class, data);
System.out.println("id -> " + config.getId());
}
}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the only section that needs to be removed. The rest of it is relevant to building configs schemas.


Schema metadata can be applied to properties using additional annotations. For example, applying limits to the min/max length of a string, or describing the types of items in an array.

Nested schema metadata can also be applied to a single field by using "stacked" schema based annotations:

```java
interface MySetConfig extends Model {
@SchemaAnnotations.Property(title = "My Set")
@SchemaAnnotations.ArraySchema(defaultValue = "[\"a\"]")
@SchemaAnnotations.StringSchema(defaultValue = "some-set-value", minLength = 1, maxLength = 1)
Set<String> getMySet();
}
```