Class AbstractJsonSchema<T,​B>

  • Type Parameters:
    T - the concrete type of the generated JSON Schema
    B - the concrete type of the JSON Schema builder
    Direct Known Subclasses:
    JsonSchema, JsonSchema

    public abstract class AbstractJsonSchema<T,​B>
    extends Object
    Encapsulates the common logic supporting OpenAPI schema generation for CRD generation.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static io.sundr.codegen.model.TypeDef BOOLEAN  
      protected static io.sundr.codegen.model.TypeRef BOOLEAN_REF  
      protected static Map<io.sundr.codegen.model.TypeRef,​String> COMMON_MAPPINGS  
      protected static io.sundr.codegen.model.TypeDef DATE  
      protected static io.sundr.codegen.model.TypeRef DATE_REF  
      protected static io.sundr.codegen.model.TypeDef DOUBLE  
      protected static io.sundr.codegen.model.TypeRef DOUBLE_REF  
      protected static io.sundr.codegen.model.TypeDef DURATION  
      protected static io.sundr.codegen.model.TypeRef DURATION_REF  
      protected static io.sundr.codegen.model.TypeDef INT  
      protected static io.sundr.codegen.model.TypeDef INT_OR_STRING  
      protected static io.sundr.codegen.model.TypeRef INT_OR_STRING_REF  
      protected static io.sundr.codegen.model.TypeRef INT_REF  
      protected static io.sundr.codegen.model.TypeDef LONG  
      protected static io.sundr.codegen.model.TypeRef LONG_REF  
      protected static io.sundr.codegen.model.TypeRef P_BOOLEAN_REF  
      protected static io.sundr.codegen.model.TypeRef P_DOUBLE_REF  
      protected static io.sundr.codegen.model.TypeRef P_INT_REF  
      protected static io.sundr.codegen.model.TypeRef P_LONG_REF  
      protected static io.sundr.codegen.model.TypeDef QUANTITY  
      protected static io.sundr.codegen.model.TypeRef QUANTITY_REF  
      protected static io.sundr.codegen.model.TypeDef STRING  
      protected static io.sundr.codegen.model.TypeRef STRING_REF  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract void addProperty​(io.sundr.codegen.model.Property property, B builder, T schema)
      Adds the specified property to the specified builder, calling internalFrom(TypeRef) to create the property schema.
      abstract T build​(B builder, List<String> required)
      Finishes up the process by actually building the final JSON schema based on the provided builder and a potentially empty list of names of fields which should be marked as required
      protected abstract T collectionProperty​(T schema)
      Builds the schema for collection properties
      protected abstract T enumProperty​(com.fasterxml.jackson.databind.JsonNode... enumValues)  
      protected T internalFrom​(io.sundr.codegen.model.TypeDef definition, String... ignore)
      Creates the JSON schema for the particular TypeDef.
      T internalFrom​(io.sundr.codegen.model.TypeRef typeRef)
      Builds the specific JSON schema representing the structural schema for the specified property
      protected abstract T mappedProperty​(io.sundr.codegen.model.TypeRef ref)
      Builds the schema for specifically handled property types (e.g.
      abstract B newBuilder()
      Creates a new specific builder object.
      protected abstract T singleProperty​(String typeName)
      Builds the schema for standard, simple (e.g.
    • Field Detail

      • QUANTITY

        protected static final io.sundr.codegen.model.TypeDef QUANTITY
      • DURATION

        protected static final io.sundr.codegen.model.TypeDef DURATION
      • INT_OR_STRING

        protected static final io.sundr.codegen.model.TypeDef INT_OR_STRING
      • BOOLEAN

        protected static final io.sundr.codegen.model.TypeDef BOOLEAN
      • STRING

        protected static final io.sundr.codegen.model.TypeDef STRING
      • INT

        protected static final io.sundr.codegen.model.TypeDef INT
      • LONG

        protected static final io.sundr.codegen.model.TypeDef LONG
      • DOUBLE

        protected static final io.sundr.codegen.model.TypeDef DOUBLE
      • DATE

        protected static final io.sundr.codegen.model.TypeDef DATE
      • QUANTITY_REF

        protected static final io.sundr.codegen.model.TypeRef QUANTITY_REF
      • DURATION_REF

        protected static final io.sundr.codegen.model.TypeRef DURATION_REF
      • INT_OR_STRING_REF

        protected static final io.sundr.codegen.model.TypeRef INT_OR_STRING_REF
      • BOOLEAN_REF

        protected static final io.sundr.codegen.model.TypeRef BOOLEAN_REF
      • STRING_REF

        protected static final io.sundr.codegen.model.TypeRef STRING_REF
      • INT_REF

        protected static final io.sundr.codegen.model.TypeRef INT_REF
      • LONG_REF

        protected static final io.sundr.codegen.model.TypeRef LONG_REF
      • DOUBLE_REF

        protected static final io.sundr.codegen.model.TypeRef DOUBLE_REF
      • DATE_REF

        protected static final io.sundr.codegen.model.TypeRef DATE_REF
      • P_INT_REF

        protected static final io.sundr.codegen.model.TypeRef P_INT_REF
      • P_LONG_REF

        protected static final io.sundr.codegen.model.TypeRef P_LONG_REF
      • P_DOUBLE_REF

        protected static final io.sundr.codegen.model.TypeRef P_DOUBLE_REF
      • P_BOOLEAN_REF

        protected static final io.sundr.codegen.model.TypeRef P_BOOLEAN_REF
      • COMMON_MAPPINGS

        protected static final Map<io.sundr.codegen.model.TypeRef,​String> COMMON_MAPPINGS
    • Constructor Detail

      • AbstractJsonSchema

        public AbstractJsonSchema()
    • Method Detail

      • internalFrom

        protected T internalFrom​(io.sundr.codegen.model.TypeDef definition,
                                 String... ignore)
        Creates the JSON schema for the particular TypeDef. This is template method where sub-classes are supposed to provide specific implementations of abstract methods.
        Parameters:
        definition - The definition.
        ignore - a potentially empty list of property names to ignore while generating the schema
        Returns:
        The schema.
      • newBuilder

        public abstract B newBuilder()
        Creates a new specific builder object.
        Returns:
        a new builder object specific to the CRD generation version
      • addProperty

        public abstract void addProperty​(io.sundr.codegen.model.Property property,
                                         B builder,
                                         T schema)
        Adds the specified property to the specified builder, calling internalFrom(TypeRef) to create the property schema.
        Parameters:
        property - the property to add to the currently being built schema
        builder - the builder representing the schema being built
        schema - the built schema for the property being added
      • build

        public abstract T build​(B builder,
                                List<String> required)
        Finishes up the process by actually building the final JSON schema based on the provided builder and a potentially empty list of names of fields which should be marked as required
        Parameters:
        builder - the builder used to build the final schema
        required - the list of names of required fields
        Returns:
        the built JSON schema
      • internalFrom

        public T internalFrom​(io.sundr.codegen.model.TypeRef typeRef)
        Builds the specific JSON schema representing the structural schema for the specified property
        Parameters:
        typeRef - the type of the property which schema we want to build
        Returns:
        the structural schema associated with the specified property
      • mappedProperty

        protected abstract T mappedProperty​(io.sundr.codegen.model.TypeRef ref)
        Builds the schema for specifically handled property types (e.g. intOrString properties)
        Parameters:
        ref - the type of the specifically handled property
        Returns:
        the property schema
      • collectionProperty

        protected abstract T collectionProperty​(T schema)
        Builds the schema for collection properties
        Parameters:
        schema - the schema for the extracted element type for this collection-like property
        Returns:
        the schema for the collection-like property
      • singleProperty

        protected abstract T singleProperty​(String typeName)
        Builds the schema for standard, simple (e.g. string) property types
        Parameters:
        typeName - the mapped name of the property type
        Returns:
        the schema for the property
      • enumProperty

        protected abstract T enumProperty​(com.fasterxml.jackson.databind.JsonNode... enumValues)