Class DiscriminatorUtils


  • public class DiscriminatorUtils
    extends Object
    • Constructor Detail

      • DiscriminatorUtils

        public DiscriminatorUtils()
    • Method Detail

      • discriminatorFound

        public static CodegenProperty discriminatorFound​(io.swagger.v3.oas.models.OpenAPI openAPI,
                                                         String composedSchemaName,
                                                         io.swagger.v3.oas.models.media.Schema sc,
                                                         String discPropName,
                                                         Set<String> visitedSchemas)
        Recursively look in Schema sc for the discriminator discPropName and return a CodegenProperty with the dataType and required params set the returned CodegenProperty may not be required, and it may not be of type string
        Parameters:
        openAPI - The openAPI specification
        composedSchemaName - The name of the sc Schema
        sc - The Schema that may contain the discriminator
        discPropName - The String that is the discriminator propertyName in the schema
        visitedSchemas - A set of visited schema names
      • getDiscriminatorPropertyType

        public static Optional<String> getDiscriminatorPropertyType​(io.swagger.v3.oas.models.media.Schema schema,
                                                                    String discriminatorPropertyName)
        Gets the simple ref name of the discriminator property type from the schema.
        Parameters:
        schema - The input OAS schema.
        discriminatorPropertyName - The name of the discriminator property.
        Returns:
        referenced type name, or an empty optional if unavailable
      • recursiveGetDiscriminator

        public static DiscriminatorUtils.DiscriminatorData recursiveGetDiscriminator​(io.swagger.v3.oas.models.OpenAPI openAPI,
                                                                                     boolean legacyDiscriminatorBehavior,
                                                                                     io.swagger.v3.oas.models.media.Schema sc,
                                                                                     ArrayList<io.swagger.v3.oas.models.media.Schema> visitedSchemas)
        Recursively look in Schema sc for the discriminator and return it
        Parameters:
        openAPI - the openAPI specification
        legacyDiscriminatorBehavior - whether legacy discriminator behavior is enabled
        sc - The Schema that may contain the discriminator
        visitedSchemas - an array list of visited schemas
      • discriminatorVendorExtensionValue

        public static Optional<String> discriminatorVendorExtensionValue​(io.swagger.v3.oas.models.media.Schema schema)
        Get the value of the vendor extension x-discriminator-value from the schema, if present.
        Parameters:
        schema - the schema to check for the vendor extension
        Returns:
        the value of the vendor extension, or an empty optional if not present
      • getDistinctTypes

        public static List<io.swagger.v3.oas.models.media.Schema> getDistinctTypes​(io.swagger.v3.oas.models.OpenAPI openAPI,
                                                                                   io.swagger.v3.oas.models.media.Schema schema,
                                                                                   String discPropName)
        Get the best matching simple types for all the mapped schemas
        Parameters:
        openAPI - The openAPI specification
        schema - The Schema that may contain the discriminator
        discPropName - The String that is the discriminator propertyName in the schema
        Returns:
        the distinct list of property Schema with the requested discPropName
      • getMappedSchemas

        public static List<io.swagger.v3.oas.models.media.Schema> getMappedSchemas​(io.swagger.v3.oas.models.OpenAPI openAPI,
                                                                                   io.swagger.v3.oas.models.media.Schema schema)
        return the list of dereferenced mapping schemas.
        Returns:
        the schemas found or empty list if not found.
      • findProperty

        public static io.swagger.v3.oas.models.media.Schema findProperty​(io.swagger.v3.oas.models.OpenAPI openAPI,
                                                                         io.swagger.v3.oas.models.media.Schema schema,
                                                                         String propertyName,
                                                                         Set<io.swagger.v3.oas.models.media.Schema> visitedSchemas)
        Recursively try to find the schema matching the propertyName.
        Returns:
        the schema found or null if not found