Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.2</version>
<version>3.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -86,7 +86,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.5</version>
<version>2.8.9</version>
</dependency>

<!-- Testing -->
Expand Down Expand Up @@ -123,7 +123,7 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.20.1</version>
<version>1.21.3</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -145,13 +145,13 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.20.1</version>
<version>1.21.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.20.1</version>
<version>1.21.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class SwaggerMeta {
private String originalTypeFqn = null;
@JsonProperty("isIdentity")
private Boolean isIdentity = null;
@JsonProperty("isCustomType")
private Boolean isCustomType = null;
@JsonProperty("isNestedStructure")
private Boolean isNestedStructure = null;
@JsonProperty("isMap")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public static String setIsIdentity(@Nullable String currentMeta, boolean value)
return OBJECT_MAPPER.writeValueAsString(meta);
}

@SneakyThrows(JsonProcessingException.class)
public static String setIsCustomType(@Nullable String currentMeta, boolean value) {
var meta = getSwaggerMeta(currentMeta);
meta.setIsCustomType(!value ? null : true);

return OBJECT_MAPPER.writeValueAsString(meta);
}

@SneakyThrows(JsonProcessingException.class)
public static String setIsNestedStructure(@Nullable String currentMeta, boolean value) {
var meta = getSwaggerMeta(currentMeta);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.aboutbits.springboot.toolbox.swagger.type;
package it.aboutbits.springboot.toolbox.swagger.customization.custom_type;

import io.swagger.v3.core.converter.AnnotatedType;
import io.swagger.v3.core.converter.ModelConverter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package it.aboutbits.springboot.toolbox.swagger.customization.custom_type;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.Schema;
import it.aboutbits.springboot.toolbox.swagger.SwaggerMetaUtil;
import it.aboutbits.springboot.toolbox.type.CustomType;
import it.aboutbits.springboot.toolbox.type.identity.EntityId;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.customizers.OpenApiCustomizer;

import static it.aboutbits.springboot.toolbox.swagger.customization.custom_type.SchemaUtil.getClassFromSchemaReference;

@Slf4j
public class CustomTypeOpenApiCustomizerForCodeGenerator implements OpenApiCustomizer {
@Override
public void customise(OpenAPI openApi) {
openApi.getComponents().getSchemas().forEach(this::updateSchema);
}


private void updateSchema(String fqn, Schema<?> schema) {
var type = getClassFromSchemaReference(fqn);

if (type.isEmpty()) {
log.debug("Can not resolve type for schema reference: {}", fqn);
return;
}

var clazz = type.get();

if (CustomType.class.isAssignableFrom(clazz)) {

var isIdentity = EntityId.class.isAssignableFrom(clazz);

var description = SwaggerMetaUtil.setOriginalTypeFqn(
schema.getDescription(),
fqn
);
description = SwaggerMetaUtil.setIsIdentity(description, isIdentity);
description = SwaggerMetaUtil.setIsCustomType(description, true);
schema.setDescription(description);
}

}
}
Loading