Skip to content

Commit

Permalink
chore(core): cleanup ToDos, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sam0r040 committed Feb 9, 2024
1 parent 2841145 commit d3eb075
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public enum InitMode {
@Nullable
private Endpoint endpoint;

@Nullable
private ConfigDocket docket;
private ConfigDocket docket = new ConfigDocket();

@Nullable
private Scanner scanner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@

import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCHEMA_EXAMPLE_GENERATOR;

// TODO: Example JsonGenerator: Traversieren vom Generieren Trennen
// TODO: Welche API brauchen wir beim Generieren? Parentmitgeben vs State im Generator

// TODO: Einfach Yaml generieren?
// TODO: Wie wird der XML Root richtig gesetzt?

@Slf4j
@ConditionalOnProperty(name = SPRINGWOLF_SCHEMA_EXAMPLE_GENERATOR, havingValue = "buildin-json", matchIfMissing = true)
@RequiredArgsConstructor
Expand Down Expand Up @@ -171,7 +166,7 @@ private String getFirstEnumValue(Schema schema) {
if (enums != null) {
Optional<String> firstEnumEntry = enums.stream().findFirst();
if (firstEnumEntry.isPresent()) {
return firstEnumEntry.get(); // TODO: Pass through example value generator
return firstEnumEntry.get();
}
}
return null;
Expand All @@ -192,7 +187,6 @@ private T handleObject(String name, Schema schema, Map<String, Schema> definitio

if (schema.getAllOf() != null && !schema.getAllOf().isEmpty()) {
List<Schema> schemas = schema.getAllOf();
// TODO lookup ref?
Schema allOfSchema = schemas.get(0);
// Open: Handle properties of all schemas, not only the first one
return buildSchemaInternal(name, allOfSchema, definitions, visited);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void processMessageFromAnnotationWithAsyncMessage(Class<?> classWithOperationBin
.messageId("simpleFoo")
.name("SimpleFooPayLoad")
.title("Message Title")
.contentType("application/schema+json;version=draft-07")
.build();
assertEquals(expectedMessage, actual.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.payload.AsyncApiPayload;
import io.github.stavshamir.springwolf.asyncapi.v3.model.channel.message.MessageObject;
import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties;
import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties.ConfigDocket;
import io.github.stavshamir.springwolf.schemas.example.DefaultSchemaWalker;
import io.github.stavshamir.springwolf.schemas.example.ExampleJsonValueGenerator;
import io.github.stavshamir.springwolf.schemas.example.SchemaWalkerProvider;
Expand All @@ -20,7 +19,6 @@
import jakarta.annotation.Nullable;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand All @@ -44,28 +42,20 @@

class DefaultJsonSchemasServiceTest {
private final SchemasPostProcessor schemasPostProcessor = Mockito.mock(SchemasPostProcessor.class);
private ComponentsService componentsService;
private final ComponentsService componentsService = new DefaultComponentsService(
List.of(),
List.of(
new ExampleGeneratorPostProcessor(new SchemaWalkerProvider(
List.of(new DefaultSchemaWalker<>(new ExampleJsonValueGenerator())))),
schemasPostProcessor),
new SwaggerSchemaUtil(),
new SpringwolfConfigProperties());

private static final ObjectMapper objectMapper =
Json.mapper().enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
private static final PrettyPrinter printer =
new DefaultPrettyPrinter().withObjectIndenter(new DefaultIndenter(" ", DefaultIndenter.SYS_LF));

@BeforeEach
void setUp() {
SpringwolfConfigProperties configProperties = new SpringwolfConfigProperties();
configProperties.setDocket(new ConfigDocket());

componentsService = new DefaultComponentsService(
List.of(),
List.of(
new ExampleGeneratorPostProcessor(new SchemaWalkerProvider(
List.of(new DefaultSchemaWalker<>(new ExampleJsonValueGenerator())))),
schemasPostProcessor),
new SwaggerSchemaUtil(),
configProperties);
}

@Test
void getSchemas() throws IOException {
componentsService.registerSchema(CompositeFoo.class);
Expand Down Expand Up @@ -157,7 +147,6 @@ void classWithSchemaAnnotation() {
void getDefinitionWithFqnClassName() throws IOException {
// given
SpringwolfConfigProperties properties = new SpringwolfConfigProperties();
properties.setDocket(new ConfigDocket());
properties.setUseFqn(true);

ComponentsService componentsServiceWithFqn =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ public class ImplementationTwo {
class AsyncApiPayloadTest {
@Test
void stringEnvelopTest() throws IOException {
// TODO fix me
componentsService.registerSchema(StringEnvelop.class, "text/xml");

String actualDefinitions = objectMapper.writer(printer).writeValueAsString(componentsService.getSchemas());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.schemas.example;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.BinarySchema;
import io.swagger.v3.oas.models.media.BooleanSchema;
Expand Down Expand Up @@ -66,7 +65,7 @@ void shouldNotHandleOtherContentType() {
class FromSchema {

@Test
void build() throws JsonProcessingException {
void build() {
StringSchema schema = new StringSchema();
schema.setName("build_schema_test");
// TODO should throw exception, just a raw value does not work in xml
Expand Down Expand Up @@ -340,7 +339,9 @@ void type_object_array() {
String actual = xmlSchemaWalker.fromSchema(schema, emptyMap()).trim();

assertThat(actual)
.isEqualTo("<type_object_array><b>true</b><s>string</s></type_object_array>".trim().stripIndent());
.isEqualTo("<type_object_array><b>true</b><s>string</s></type_object_array>"
.trim()
.stripIndent());
}

@Test
Expand Down Expand Up @@ -385,9 +386,10 @@ void composite_object_without_references() {
xmlSchemaWalker.fromSchema(schema, emptyMap()).trim().stripIndent();

assertThat(actual)
.isEqualTo("<CompositeObjectWithoutReferences><b>true</b><s>string</s></CompositeObjectWithoutReferences>"
.trim()
.stripIndent());
.isEqualTo(
"<CompositeObjectWithoutReferences><b>true</b><s>string</s></CompositeObjectWithoutReferences>"
.trim()
.stripIndent());
}

@Test
Expand All @@ -411,9 +413,10 @@ void composite_object_with_references() {
.stripIndent();

assertThat(actual)
.isEqualTo("<composite_object_with_references_root><f><b>true</b><s>string</s></f><s>string</s></composite_object_with_references_root>"
.trim()
.stripIndent());
.isEqualTo(
"<composite_object_with_references_root><f><b>true</b><s>string</s></f><s>string</s></composite_object_with_references_root>"
.trim()
.stripIndent());
}

@Test
Expand Down

0 comments on commit d3eb075

Please sign in to comment.