Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-frak committed Jan 16, 2020
1 parent ff5344c commit bbee412
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>springdoc-openapi-programmatic-documentation</artifactId>
<version>1.0.2-SNAPSHOT</version>

<name>Springdoc OpenAPI Programmatic Documenation</name>
<name>Springdoc OpenAPI Programmatic Documentation</name>
<description>Allows for defining OpenAPI documentation using code</description>
<url>https://www.code.danielfrak.com</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
@Component
public class ModelDocumentation implements ModelConverter {

private Map<Class<?>, Class<?>> classMap = new HashMap<>();
private Map<Class<?>, Class<?>> implementationMap = new HashMap<>();
private Map<Class<?>, Schema<?>> schemaMap = new HashMap<>();

public ModelDocumentation add(DocumentedModel model) {
if(model.sourceClass == null) {
if (model.sourceClass == null) {
throw new IllegalArgumentException("Source class cannot be NULL");
}
if(model.implementation != null) {
classMap.put(model.sourceClass, model.implementation);
if (model.implementation != null) {
implementationMap.put(model.sourceClass, model.implementation);
}
if(model.schema != null) {
if (model.schema != null) {
schemaMap.put(model.sourceClass, model.schema);
}
return this;
Expand All @@ -51,8 +51,8 @@ public ModelDocumentation add(DocumentedModel model) {
public Schema<?> resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
Class<?> typeClass = TypeFactory.rawClass(type.getType());

if (classMap.containsKey(typeClass)) {
type.setType(classMap.get(typeClass));
if (implementationMap.containsKey(typeClass)) {
type.setType(implementationMap.get(typeClass));
}

try {
Expand All @@ -77,7 +77,7 @@ private Schema<?> overrideSchema(Class<?> typeName, Schema<?> model) throws Ille

Schema<?> schema = schemaMap.get(typeName);

for(Field field: schema.getClass().getDeclaredFields()) {
for (Field field : schema.getClass().getDeclaredFields()) {
field.setAccessible(true);

if (isBlank(field.get(model))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.danielfrak.code.programmaticdocs;

import com.danielfrak.code.programmaticdocs.ModelDocumentation.DocumentedModel;
import com.danielfrak.code.programmaticdocs.dummies.DummyObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.core.converter.AnnotatedType;
import io.swagger.v3.core.converter.ModelConverter;
Expand All @@ -25,11 +26,11 @@
@ExtendWith(MockitoExtension.class)
class ModelDocumentationTest {

private ModelDocumentation modelDocumentation;

@Mock
private ModelConverterContext modelConverterContext;

private ModelDocumentation modelDocumentation;

@BeforeEach
void setUp() {
modelDocumentation = new ModelDocumentation();
Expand Down Expand Up @@ -99,7 +100,4 @@ void willNotChangeValueSchemaWhenAlreadyDefined() {
assertEquals(existingDescriptionValue, schema.getDescription());
assertEquals(exampleValue, schema.getExample());
}

private static class DummyObject {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.danielfrak.code.programmaticdocs.dummies;

public class DummyObject {
}

0 comments on commit bbee412

Please sign in to comment.