gravitee-io / issues

Gravitee.io - API Platform - Issues
64 stars 26 forks source link

Support interface/extended classes for plugin policy configuration #2384

Open fmigneault opened 5 years ago

fmigneault commented 5 years ago

Is there a possibility to consider using https://github.com/mbknor/mbknor-jackson-jsonSchema for https://github.com/gravitee-io/json-schema-generator-maven-plugin in order to support plugin policy JSON schema generation using class inheritance?

More specifically, it would be great to support objects using anyOf or oneOf structures in cases where one object configuration or another can be specified for a given policy implementation.

With below example, both Deer and Llama would be valid objects that could be used to configured the same policy field.

public interface Herbivore{<...>}
public class Animal{<...>}
public class Deer extends Animal implements Herbivore{<...>}
public class Llama extends Animal implements Herbivore{<...>}
public AnimalPolicyConfiguration implements PolicyConfiguration {
   private Animal; 
   // getter; setter;
}

Expected Behavior

Using a selector, one of the specialization classes as defined in the JSON schema oneOf can be selected, and corresponding fields are displayed in the UI.

On the API side, the schema validation should allow the supported cases. Appropriate extending class be enforced via an enum as proposed here: https://github.com/FasterXML/jackson-module-jsonSchema/issues/5#issuecomment-54288139

An explicit example of the expected behaviour is presented here: https://stackoverflow.com/questions/56174997/json-schema-generator-with-inheritance-and-references This example's solution uses https://github.com/mbknor/mbknor-jackson-jsonSchema proposed above.

Current Behavior

An interface class that is extended by valid classes cannot be "selected" to be specialized with appropriate type in the API management UI. The generated JSON only defines an object with type any, which doesn't provide specialized object fields to fill from the management API and UI.

Possible Solution

see above links

Your Environment

brasseld commented 5 years ago

Hi @fmigneault

It would be awesome, but unfortunately, I'm not sure that the library we're relying on to render policy configuration through the UI is able to manage this inheritance / composition / ... from json schema

See http://schemaform.io/

fmigneault commented 5 years ago

@brasseld Is there a way that the UI could be reactive to a user input?

Using my previous example, a combobox/selector would offer types [Deer, Llama]. Upon selection of one or the other, the form to be applied would be resolved with corresponding object by ID using the normal conversion method used by http://schemaform.io/, by providing only the corresponding object's definition.

brasseld commented 5 years ago

According to some of the examples, it seems to be possible.

Did you see them http://schemaform.io/examples/bootstrap-example.html ?

fmigneault commented 5 years ago

I see, yes it does seem possible according to these examples to make conditional forms. I am wondering though how these conditions could be generated from the schemas alone? If I’m understanding correctly, the forms’ JSON structures are obtained from the JSON schemas generated by the maven plugin?

fmigneault commented 5 years ago

@brasseld I found this example that shows exactly the results that would be expected with a selector of corresponding object inputs, and the form schema that should support it.