|
61 | 61 | public abstract class AnnotationsUtils { |
62 | 62 |
|
63 | 63 | private static final Logger LOGGER = LoggerFactory.getLogger(AnnotationsUtils.class); |
| 64 | + private static final String NULL_TYPE = "null"; |
| 65 | + private static final String STRING_TYPE = "string"; |
64 | 66 | public static final String COMPONENTS_REF = Components.COMPONENTS_SCHEMAS_REF; |
65 | 67 |
|
66 | 68 | public static boolean hasSchemaAnnotation(io.swagger.v3.oas.annotations.media.Schema schema) { |
@@ -1003,7 +1005,7 @@ public static List<Object> parseExamplesArray(io.swagger.v3.oas.annotations.medi |
1003 | 1005 | // Only parse "null" as null value when nullable=true |
1004 | 1006 | if (node.isNull() && schema.nullable()) { |
1005 | 1007 | parsedExamples.add(null); |
1006 | | - } else if (schemaObject == null && "string".equals(schema.type())) { |
| 1008 | + } else if (schemaObject == null && STRING_TYPE.equals(schema.type())) { |
1007 | 1009 | parsedExamples.add(trimmed); |
1008 | 1010 | } else if (shouldUseNodeAsExample(node, schemaObject)) { |
1009 | 1011 | parsedExamples.add(node); |
@@ -1081,7 +1083,7 @@ public static Schema resolveSchemaFromType(Class<?> schemaImplementation, |
1081 | 1083 | } |
1082 | 1084 | if (StringUtils.isBlank(existingSchemaObject.get$ref()) && StringUtils.isBlank(existingSchemaObject.getType())) { |
1083 | 1085 | // default to string |
1084 | | - existingSchemaObject.setType("string"); |
| 1086 | + existingSchemaObject.setType(STRING_TYPE); |
1085 | 1087 | } |
1086 | 1088 | return existingSchemaObject; |
1087 | 1089 | } |
@@ -1711,7 +1713,7 @@ public static Type getSchemaType(io.swagger.v3.oas.annotations.media.Schema sche |
1711 | 1713 | } |
1712 | 1714 | case "boolean": |
1713 | 1715 | return Boolean.class; |
1714 | | - case "string": |
| 1716 | + case STRING_TYPE: |
1715 | 1717 | return String.class; |
1716 | 1718 | default: |
1717 | 1719 | if (nullIfNotFound) { |
@@ -1949,26 +1951,28 @@ public static Optional<? extends Schema> getSchema(io.swagger.v3.oas.annotations |
1949 | 1951 | } else { |
1950 | 1952 | Optional<Schema> schemaFromAnnotation = AnnotationsUtils.getSchemaFromAnnotation(schemaAnnotation, components, jsonViewAnnotation, openapi31, null, context); |
1951 | 1953 | if (schemaFromAnnotation.isPresent()) { |
1952 | | - if (StringUtils.isBlank(schemaFromAnnotation.get().get$ref()) && StringUtils.isBlank(schemaFromAnnotation.get().getType()) && !(schemaFromAnnotation.get() instanceof ComposedSchema)) { |
| 1954 | + Schema schema = schemaFromAnnotation.get(); |
| 1955 | + if (StringUtils.isBlank(schema.get$ref()) && StringUtils.isBlank(schema.getType()) && !(schema instanceof ComposedSchema)) { |
1953 | 1956 | // default to string |
1954 | | - schemaFromAnnotation.get().setType("string"); |
| 1957 | + schema.setType(STRING_TYPE); |
1955 | 1958 | } |
1956 | | - return Optional.of(schemaFromAnnotation.get()); |
| 1959 | + return Optional.of(schema); |
1957 | 1960 | } else { |
1958 | 1961 | Optional<Schema> arraySchemaFromAnnotation = AnnotationsUtils.getArraySchema(arrayAnnotation, components, jsonViewAnnotation, openapi31, null, false, context); |
1959 | 1962 | if (arraySchemaFromAnnotation.isPresent()) { |
1960 | | - if (arraySchemaFromAnnotation.get().getItems() != null && StringUtils.isBlank(arraySchemaFromAnnotation.get().getItems().get$ref()) && StringUtils.isBlank(arraySchemaFromAnnotation.get().getItems().getType())) { |
| 1963 | + Schema schema = arraySchemaFromAnnotation.get(); |
| 1964 | + Schema schemaItems = schema.getItems(); |
| 1965 | + if (schemaItems != null && StringUtils.isBlank(schemaItems.get$ref()) && StringUtils.isBlank(schemaItems.getType())) { |
1961 | 1966 | // default to string |
1962 | | - arraySchemaFromAnnotation.get().getItems().setType("string"); |
| 1967 | + schemaItems.setType(STRING_TYPE); |
1963 | 1968 | } |
1964 | | - return Optional.of(arraySchemaFromAnnotation.get()); |
| 1969 | + return Optional.of(schema); |
1965 | 1970 | } |
1966 | 1971 | } |
1967 | 1972 | } |
1968 | 1973 | return Optional.empty(); |
1969 | 1974 | } |
1970 | 1975 |
|
1971 | | - |
1972 | 1976 | public static void applyTypes(String[] classTypes, String[] methodTypes, Content content, MediaType mediaType) { |
1973 | 1977 | if (methodTypes != null && methodTypes.length > 0) { |
1974 | 1978 | for (String value : methodTypes) { |
|
0 commit comments