Skip to content

Commit

Permalink
Fix #117 (#120)
Browse files Browse the repository at this point in the history
Register String schema for String payloads.
  • Loading branch information
stavshamir authored Dec 3, 2022
1 parent b30891f commit 514fa67
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.swagger.v3.core.converter.ModelConverters;
import io.swagger.v3.oas.models.media.MapSchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -64,6 +65,11 @@ public String register(Class<?> type) {
Map<String, Schema> schemas = converter.readAll(type);
this.definitions.putAll(schemas);

if (schemas.size() == 0 && type.equals(String.class)) {
this.definitions.put("String", new StringSchema());
return "String";
}

if (schemas.size() == 1) {
return new ArrayList<>(schemas.keySet()).get(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;

public class DefaultSchemasServiceTest {

Expand All @@ -29,6 +30,16 @@ public class DefaultSchemasServiceTest {
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}

@Test
public void string() throws IOException, JSONException {
String modelName = schemasService.register(String.class);

assertThat(modelName)
.isEqualTo("String");

assertNotNull(schemasService.getDefinitions().get(modelName));
}

@Test
public void simpleObject() throws IOException, JSONException {
String modelName = schemasService.register(SimpleFoo.class);
Expand Down

0 comments on commit 514fa67

Please sign in to comment.