1
- package org .springdoc .core .converters ;/**
2
- * @author bnasslahsen
3
- */ public class SortOpenAPIConverter {
4
- }
1
+ package org .springdoc .core .converters ;
2
+
3
+ /*
4
+ *
5
+ * *
6
+ * * *
7
+ * * * * Copyright 2019-2022 the original author or authors.
8
+ * * * *
9
+ * * * * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * * * * you may not use this file except in compliance with the License.
11
+ * * * * You may obtain a copy of the License at
12
+ * * * *
13
+ * * * * https://www.apache.org/licenses/LICENSE-2.0
14
+ * * * *
15
+ * * * * Unless required by applicable law or agreed to in writing, software
16
+ * * * * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * * * * See the License for the specific language governing permissions and
19
+ * * * * limitations under the License.
20
+ * * *
21
+ * *
22
+ *
23
+ */
24
+ import java .util .Iterator ;
25
+
26
+ import com .fasterxml .jackson .databind .JavaType ;
27
+ import io .swagger .v3 .core .converter .AnnotatedType ;
28
+ import io .swagger .v3 .core .converter .ModelConverter ;
29
+ import io .swagger .v3 .core .converter .ModelConverterContext ;
30
+ import io .swagger .v3 .oas .models .media .Schema ;
31
+ import org .apache .commons .lang3 .StringUtils ;
32
+ import org .springdoc .core .converters .models .Sort ;
33
+ import org .springdoc .core .providers .ObjectMapperProvider ;
34
+
35
+ /**
36
+ * The Spring Data Sort type model converter.
37
+ * @author daniel-shuy
38
+ */
39
+ public class SortOpenAPIConverter implements ModelConverter {
40
+
41
+ private static final String SORT_TO_REPLACE = "org.springframework.data.domain.Sort" ;
42
+
43
+ /**
44
+ * The constant SORT.
45
+ */
46
+ private static final AnnotatedType SORT = new AnnotatedType (Sort .class ).resolveAsRef (true );
47
+
48
+ /**
49
+ * The Spring doc object mapper.
50
+ */
51
+ private final ObjectMapperProvider springDocObjectMapper ;
52
+
53
+ /**
54
+ * Instantiates a new Sort open api converter.
55
+ *
56
+ * @param springDocObjectMapper the spring doc object mapper
57
+ */
58
+ public SortOpenAPIConverter (ObjectMapperProvider springDocObjectMapper ) {
59
+ this .springDocObjectMapper = springDocObjectMapper ;
60
+ }
61
+
62
+ /**
63
+ * Resolve schema.
64
+ *
65
+ * @param type the type
66
+ * @param context the context
67
+ * @param chain the chain
68
+ * @return the schema
69
+ */
70
+ @ Override
71
+ public Schema resolve (AnnotatedType type , ModelConverterContext context , Iterator <ModelConverter > chain ) {
72
+ JavaType javaType = springDocObjectMapper .jsonMapper ().constructType (type .getType ());
73
+ if (javaType != null ) {
74
+ Class <?> cls = javaType .getRawClass ();
75
+ if (SORT_TO_REPLACE .equals (cls .getCanonicalName ())) {
76
+ if (!type .isSchemaProperty ())
77
+ type = SORT ;
78
+ else
79
+ type .name (cls .getSimpleName () + StringUtils .capitalize (type .getParent ().getType ()));
80
+ }
81
+ }
82
+ return (chain .hasNext ()) ? chain .next ().resolve (type , context , chain ) : null ;
83
+ }
84
+
85
+ }
0 commit comments