Skip to content

Commit 2e7f6f5

Browse files
authored
Merge pull request #25 from aboutbits/update-swagger
update swagger tooling for code generator
2 parents caec21a + 3885bff commit 2e7f6f5

30 files changed

Lines changed: 489 additions & 185 deletions

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.4.2</version>
9+
<version>3.4.5</version>
1010
<relativePath/> <!-- lookup parent from repository -->
1111
</parent>
1212

@@ -86,7 +86,7 @@
8686
<dependency>
8787
<groupId>org.springdoc</groupId>
8888
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
89-
<version>2.8.5</version>
89+
<version>2.8.9</version>
9090
</dependency>
9191

9292
<!-- Testing -->
@@ -123,7 +123,7 @@
123123
<dependency>
124124
<groupId>org.testcontainers</groupId>
125125
<artifactId>testcontainers</artifactId>
126-
<version>1.20.1</version>
126+
<version>1.21.3</version>
127127
<scope>test</scope>
128128
<exclusions>
129129
<exclusion>
@@ -145,13 +145,13 @@
145145
<dependency>
146146
<groupId>org.testcontainers</groupId>
147147
<artifactId>junit-jupiter</artifactId>
148-
<version>1.20.1</version>
148+
<version>1.21.3</version>
149149
<scope>test</scope>
150150
</dependency>
151151
<dependency>
152152
<groupId>org.testcontainers</groupId>
153153
<artifactId>postgresql</artifactId>
154-
<version>1.20.1</version>
154+
<version>1.21.3</version>
155155
<scope>test</scope>
156156
</dependency>
157157
</dependencies>

src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/swagger/RegisterCustomTypesWithSwagger.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/main/java/it/aboutbits/springboot/toolbox/swagger/SwaggerMeta.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class SwaggerMeta {
1212
private String originalTypeFqn = null;
1313
@JsonProperty("isIdentity")
1414
private Boolean isIdentity = null;
15+
@JsonProperty("isCustomType")
16+
private Boolean isCustomType = null;
1517
@JsonProperty("isNestedStructure")
1618
private Boolean isNestedStructure = null;
1719
@JsonProperty("isMap")

src/main/java/it/aboutbits/springboot/toolbox/swagger/SwaggerMetaUtil.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ public static String setIsIdentity(@Nullable String currentMeta, boolean value)
4646
return OBJECT_MAPPER.writeValueAsString(meta);
4747
}
4848

49+
@SneakyThrows(JsonProcessingException.class)
50+
public static String setIsCustomType(@Nullable String currentMeta, boolean value) {
51+
var meta = getSwaggerMeta(currentMeta);
52+
meta.setIsCustomType(!value ? null : true);
53+
54+
return OBJECT_MAPPER.writeValueAsString(meta);
55+
}
56+
4957
@SneakyThrows(JsonProcessingException.class)
5058
public static String setIsNestedStructure(@Nullable String currentMeta, boolean value) {
5159
var meta = getSwaggerMeta(currentMeta);

src/main/java/it/aboutbits/springboot/toolbox/swagger/annotations/SwaggerScopedAuth.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/java/it/aboutbits/springboot/toolbox/swagger/customization/authorization_docs/AuthorizationDescriptor.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java renamed to src/main/java/it/aboutbits/springboot/toolbox/swagger/customization/custom_type/CustomTypeModelConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package it.aboutbits.springboot.toolbox.swagger.type;
1+
package it.aboutbits.springboot.toolbox.swagger.customization.custom_type;
22

33
import io.swagger.v3.core.converter.AnnotatedType;
44
import io.swagger.v3.core.converter.ModelConverter;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package it.aboutbits.springboot.toolbox.swagger.customization.custom_type;
2+
3+
import io.swagger.v3.oas.models.OpenAPI;
4+
import io.swagger.v3.oas.models.media.Schema;
5+
import it.aboutbits.springboot.toolbox.swagger.SwaggerMetaUtil;
6+
import it.aboutbits.springboot.toolbox.type.CustomType;
7+
import it.aboutbits.springboot.toolbox.type.identity.EntityId;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.springdoc.core.customizers.OpenApiCustomizer;
10+
11+
import static it.aboutbits.springboot.toolbox.swagger.customization.custom_type.SchemaUtil.getClassFromSchemaReference;
12+
13+
@Slf4j
14+
public class CustomTypeOpenApiCustomizerForCodeGenerator implements OpenApiCustomizer {
15+
@Override
16+
public void customise(OpenAPI openApi) {
17+
openApi.getComponents().getSchemas().forEach(this::updateSchema);
18+
}
19+
20+
21+
private void updateSchema(String fqn, Schema<?> schema) {
22+
var type = getClassFromSchemaReference(fqn);
23+
24+
if (type.isEmpty()) {
25+
log.debug("Can not resolve type for schema reference: {}", fqn);
26+
return;
27+
}
28+
29+
var clazz = type.get();
30+
31+
if (CustomType.class.isAssignableFrom(clazz)) {
32+
33+
var isIdentity = EntityId.class.isAssignableFrom(clazz);
34+
35+
var description = SwaggerMetaUtil.setOriginalTypeFqn(
36+
schema.getDescription(),
37+
fqn
38+
);
39+
description = SwaggerMetaUtil.setIsIdentity(description, isIdentity);
40+
description = SwaggerMetaUtil.setIsCustomType(description, true);
41+
schema.setDescription(description);
42+
}
43+
44+
}
45+
}

0 commit comments

Comments
 (0)