Class ExpandedTypeDescription

java.lang.Object
org.yaml.snakeyaml.TypeDescription
io.helidon.microprofile.openapi.ExpandedTypeDescription

public class ExpandedTypeDescription extends org.yaml.snakeyaml.TypeDescription
Extension of TypeDescription that handles:
  • nested enums,
  • extensible types,
  • references, and
  • additional properties (which can be either Boolean or Schema).

The OpenAPI document format uses lower-case enum names and values, while the SmallRye definitions use upper-case. This class simplifies adding the special handling for enums declared within a particular class.

Some of the MP OpenAPI items are extensible, meaning they accept sub-item keys with the "x-" prefix. This class supports extensions. For scalars it delegates to the normal SnakeYAML processing to correctly type and parse the scalar. For sequences it creates Lists. For mappings it creates Maps. The sub-nodes of the lists and maps are handled by the normal SnakeYAML parsing, so the resulting elements in lists and maps are of the SnakeYAML-inferred types.

A sub-node $ref maps to the ref property on the MP OpenAPI types. This type description simplifies defining the $ref property to those types that support it.

In schemas, the additionalProperties value can be either a boolean or a schema. The MicroProfile Schema type exposes getAdditionalPropertiesBoolean, setAdditionalPropertiesBoolean, getAdditionalPropertiesSchema, and setAdditionalPropertiesSchema methods. We do not know until runtime and the value is available for each additionalProperties instance which type (Boolean or Schema) to use, so we cannot just prepare a smart SnakeYAML Property implementation. Instead we augment the schema-specific TypeDescription so it knows how to decide, at runtime, what to do.

We use this expanded version of TypeDescription with the generated SnakeYAMLParserHelper class.

  • Method Details

    • create

      public static ExpandedTypeDescription create(Class<?> clazz, Class<?> impl)
      Factory method for ease of chaining other method invocations.
      Parameters:
      clazz - interface type to describe
      impl - implementation class for the interface
      Returns:
      resulting TypeDescription
    • addRef

      public ExpandedTypeDescription addRef()
      Adds property handling for a $ref reference.
      Returns:
      this type description
    • addExtensions

      public ExpandedTypeDescription addExtensions()
      Adds property handling for extensions.
      Returns:
      this type description
    • getProperty

      public org.yaml.snakeyaml.introspector.Property getProperty(String name)
      Overrides:
      getProperty in class org.yaml.snakeyaml.TypeDescription
    • setupPropertyType

      public boolean setupPropertyType(String key, org.yaml.snakeyaml.nodes.Node valueNode)
      Overrides:
      setupPropertyType in class org.yaml.snakeyaml.TypeDescription
    • newInstance

      public Object newInstance(String propertyName, org.yaml.snakeyaml.nodes.Node node)
      Overrides:
      newInstance in class org.yaml.snakeyaml.TypeDescription
    • addExcludes

      public void addExcludes(String... propNames)
      Add property names excludes.
      Parameters:
      propNames - names to exclude
    • impl

      public Class<?> impl()
      Returns the implementation class associated with this type descr.
      Returns:
      implementation class
    • hasDefaultProperty

      public boolean hasDefaultProperty()
      Whether a default value exists.
      Returns:
      true if default value property is defined