Package org.openapitools.codegen.utils
Class DiscriminatorUtils
- java.lang.Object
-
- org.openapitools.codegen.utils.DiscriminatorUtils
-
public class DiscriminatorUtils extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDiscriminatorUtils.DiscriminatorData
-
Constructor Summary
Constructors Constructor Description DiscriminatorUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CodegenPropertydiscriminatorFound(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 stringstatic Optional<String>discriminatorVendorExtensionValue(io.swagger.v3.oas.models.media.Schema schema)Get the value of the vendor extensionx-discriminator-valuefrom the schema, if present.static io.swagger.v3.oas.models.media.SchemafindProperty(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.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.static StringgetDiscriminatorSchemaError(CodegenProperty codegenProperty, String discPropName, String modelName, String composedSchemaName)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 schemasstatic 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.static DiscriminatorUtils.DiscriminatorDatarecursiveGetDiscriminator(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
-
-
-
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 specificationcomposedSchemaName- The name of the sc Schemasc- The Schema that may contain the discriminatordiscPropName- The String that is the discriminator propertyName in the schemavisitedSchemas- 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 specificationlegacyDiscriminatorBehavior- whether legacy discriminator behavior is enabledsc- The Schema that may contain the discriminatorvisitedSchemas- 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 extensionx-discriminator-valuefrom 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
-
getDiscriminatorSchemaError
public static String getDiscriminatorSchemaError(CodegenProperty codegenProperty, String discPropName, String modelName, String composedSchemaName)
-
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 specificationschema- The Schema that may contain the discriminatordiscPropName- 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
-
-