Skip to content

Commit

Permalink
feat(core): remove studio work-around for yaml (#898)
Browse files Browse the repository at this point in the history
* feat(core): remove studio work-around for yaml

Since js `@asyncapi/parser@3.2.1`, the workaround for async api studio for date strings to need quotes is no longer needed

* chore(core): remove unused jackson-dataformat-yaml from dependency list
  • Loading branch information
timonback authored Aug 16, 2024
1 parent 0600e69 commit 8609c89
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 73 deletions.
1 change: 0 additions & 1 deletion springwolf-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dependencies {

implementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}"

implementation "org.slf4j:slf4j-api:${slf4jApiVersion}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,11 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties;
import io.swagger.v3.core.util.Yaml;

public class DefaultExampleYamlValueSerializer implements ExampleYamlValueSerializer {

private final ObjectMapper yamlMapper;

public DefaultExampleYamlValueSerializer(SpringwolfConfigProperties springwolfConfigProperties) {
this.yamlMapper = Yaml.mapper();

if (springwolfConfigProperties.isStudioCompatibility()) {
// AsyncApi Studio has problems with missing quotes on dates, so we add quotes on every example
// see https://github.com/springwolf/springwolf-core/issues/820
((YAMLFactory) yamlMapper.getFactory()).disable(YAMLGenerator.Feature.MINIMIZE_QUOTES);
}
}
private final ObjectMapper yamlMapper = Yaml.mapper();

@Override
public String writeDocumentAsYamlString(JsonNode node) throws JsonProcessingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ public SchemaWalker xmlSchemaWalker(ExampleXmlValueSerializer exampleXmlValueSer

@Bean
@ConditionalOnMissingBean
public ExampleYamlValueSerializer defaultExampleYamlValueSerializer(
SpringwolfConfigProperties springwolfConfigProperties) {
return new DefaultExampleYamlValueSerializer(springwolfConfigProperties);
public ExampleYamlValueSerializer defaultExampleYamlValueSerializer() {
return new DefaultExampleYamlValueSerializer();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ class DefaultYamlComponentsServiceIntegrationTest {

private final SpringwolfConfigProperties springwolfConfigProperties = new SpringwolfConfigProperties();
private final ExampleYamlValueGenerator exampleYamlValueGenerator = new ExampleYamlValueGenerator(
new ExampleJsonValueGenerator(),
new DefaultExampleYamlValueSerializer(springwolfConfigProperties),
springwolfConfigProperties);
new ExampleJsonValueGenerator(), new DefaultExampleYamlValueSerializer(), springwolfConfigProperties);

private final SwaggerSchemaService schemaService = new SwaggerSchemaService(
List.of(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ class DefaultSchemaWalkerYamlIntegrationTest {

private final SpringwolfConfigProperties springwolfConfigProperties = new SpringwolfConfigProperties();
private final ExampleYamlValueGenerator exampleYamlValueGenerator = new ExampleYamlValueGenerator(
new ExampleJsonValueGenerator(),
new DefaultExampleYamlValueSerializer(springwolfConfigProperties),
springwolfConfigProperties);
new ExampleJsonValueGenerator(), new DefaultExampleYamlValueSerializer(), springwolfConfigProperties);
private final DefaultSchemaWalker<JsonNode, String> jsonSchemaWalker =
new DefaultSchemaWalker<>(exampleYamlValueGenerator);

Expand Down Expand Up @@ -73,7 +71,7 @@ void build(TestInfo testInfo) {
String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap());

assertThat(actualString).isEqualTo("""
"string"
string
""");
}

Expand Down Expand Up @@ -242,7 +240,7 @@ void type_string(TestInfo testInfo) {
String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap());

assertThat(actualString).isEqualTo("""
"string"
string
""");
}

Expand All @@ -255,7 +253,7 @@ void type_string_default_set(TestInfo testInfo) {
String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap());

assertThat(actualString).isEqualTo("""
"custom-example-value"
custom-example-value
""");
}

Expand All @@ -268,7 +266,7 @@ void type_string_example_set(TestInfo testInfo) {
String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap());

assertThat(actualString).isEqualTo("""
"custom-example-value"
custom-example-value
""");
}

Expand All @@ -282,7 +280,7 @@ void type_string_from_enum(TestInfo testInfo) {
String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap());

assertThat(actualString).isEqualTo("""
"EnumItem1"
EnumItem1
""");
}

Expand All @@ -295,7 +293,7 @@ void type_string_format_byte(TestInfo testInfo) {
String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap());

assertThat(actualString).isEqualTo("""
"YmFzZTY0LWV4YW1wbGU="
YmFzZTY0LWV4YW1wbGU=
""");
}

Expand All @@ -321,7 +319,7 @@ void type_string_format_date(TestInfo testInfo) {
String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap());

assertThat(actualString).isEqualTo("""
"2015-07-20"
2015-07-20
""");
}

Expand All @@ -334,7 +332,7 @@ void type_string_format_datetime(TestInfo testInfo) {

assertThat(actualString)
.isEqualTo("""
"2015-07-20T15:49:04-07:00"
2015-07-20T15:49:04-07:00
""");
}

Expand All @@ -346,7 +344,7 @@ void type_string_format_email(TestInfo testInfo) {
String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap());

assertThat(actualString).isEqualTo("""
"example@example.com"
example@example.com
""");
}

Expand All @@ -358,7 +356,7 @@ void type_string_format_password(TestInfo testInfo) {
String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap());

assertThat(actualString).isEqualTo("""
"string-password"
string-password
""");
}

Expand All @@ -371,7 +369,7 @@ void type_string_format_uuid(TestInfo testInfo) {

assertThat(actualString)
.isEqualTo("""
"3fa85f64-5717-4562-b3fc-2c963f66afa6"
3fa85f64-5717-4562-b3fc-2c963f66afa6
""");
}

Expand Down Expand Up @@ -417,7 +415,7 @@ void type_primitive_array(TestInfo testInfo) {
String actualString = jsonSchemaWalker.fromSchema(schema, emptyMap());

assertThat(actualString).isEqualTo("""
- "string"
- string
""");
}
}
Expand All @@ -440,7 +438,7 @@ void type_object_array(TestInfo testInfo) {
.isEqualTo(
"""
- b: true
s: "string"
s: string
""");
}

Expand All @@ -456,7 +454,7 @@ void composite_object_without_references(TestInfo testInfo) {
assertThat(actualString)
.isEqualTo("""
b: true
s: "string"
s: string
""");
}

Expand All @@ -480,8 +478,8 @@ void composite_object_with_references(TestInfo testInfo) {
"""
f:
b: true
s: "string"
s: "string"
s: string
s: string
""");
}

Expand All @@ -497,7 +495,7 @@ void object_with_anyOf(TestInfo testInfo) {
String actualString = jsonSchemaWalker.fromSchema(compositeSchema, Map.of("Nested", propertySchema));

assertThat(actualString).isEqualTo("""
anyOfField: "string"
anyOfField: string
""");
}

Expand All @@ -513,7 +511,7 @@ void object_with_oneOf(TestInfo testInfo) {
String actualString = jsonSchemaWalker.fromSchema(compositeSchema, Map.of("Nested", propertySchema));

assertThat(actualString).isEqualTo("""
oneOfField: "string"
oneOfField: string
""");
}

Expand All @@ -538,7 +536,7 @@ void object_with_allOf(TestInfo testInfo) {
.isEqualTo(
"""
allOfField:
field1: "string"
field1: string
field2: 1.1
""");
}
Expand All @@ -553,7 +551,7 @@ void object_with_map(TestInfo testInfo) {

String actualString = jsonSchemaWalker.fromSchema(mapSchema, Map.of());

assertThat(actualString).isEqualTo("key: \"string\"\n");
assertThat(actualString).isEqualTo("key: string\n");
}

@Test
Expand All @@ -572,7 +570,7 @@ void object_with_map_and_set(TestInfo testInfo) {

String actualString = jsonSchemaWalker.fromSchema(mapSchema, Map.of());

assertThat(actualString).isEqualTo("key:\n- field1: \"string\"\n");
assertThat(actualString).isEqualTo("key:\n- field1: string\n");
}

@Test
Expand All @@ -586,7 +584,7 @@ void schema_with_problematic_object_toString_example(TestInfo testInfo) {
assertThat(actualString)
.isEqualTo(
"""
"Text with special character /\\\\\\\\'\\\\b\\\\f\\\\t\\\\r\\\\n."
Text with special character /\\\\'\\b\\f\\t\\r\\n.
""");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$SchemaWithOneOf$AllOf" : {
"type" : "string",
"examples" : [ "firstOne: \"string\"\nfirstTwo: 0\nsecondOne: \"string\"\nsecondTwo: true\n" ],
"examples" : [ "firstOne: string\nfirstTwo: 0\nsecondOne: string\nsecondTwo: true\n" ],
"allOf" : [ {
"$ref" : "#/components/schemas/io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$SchemaWithOneOf$ImplementationOne"
}, {
Expand All @@ -10,7 +10,7 @@
},
"io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$SchemaWithOneOf$AnyOf" : {
"type" : "string",
"examples" : [ "firstOne: \"string\"\nsecondOne: \"string\"\n" ],
"examples" : [ "firstOne: string\nsecondOne: string\n" ],
"anyOf" : [ {
"$ref" : "#/components/schemas/io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$SchemaWithOneOf$ImplementationOne"
}, {
Expand All @@ -27,7 +27,7 @@
"type" : "string"
}
},
"examples" : [ "firstOne: \"string\"\nsecondOne: \"string\"\n" ]
"examples" : [ "firstOne: string\nsecondOne: string\n" ]
},
"io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$SchemaWithOneOf$ImplementationTwo" : {
"type" : "string",
Expand All @@ -44,7 +44,7 @@
},
"io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$SchemaWithOneOf$OneOf" : {
"type" : "string",
"examples" : [ "\"firstOne: \\\"string\\\"\\nsecondOne: \\\"string\\\"\\n\"\n" ],
"examples" : [ "|\n firstOne: string\n secondOne: string\n" ],
"oneOf" : [ {
"$ref" : "#/components/schemas/io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$SchemaWithOneOf$ImplementationOne"
}, {
Expand All @@ -67,6 +67,6 @@
"$ref" : "#/components/schemas/io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$SchemaWithOneOf$OneOf"
}
},
"examples" : [ "allOf: \"firstOne: \\\"string\\\"\\nfirstTwo: 0\\nsecondOne: \\\"string\\\"\\nsecondTwo: true\\n\"\nanyOf: \"firstOne: \\\"string\\\"\\nsecondOne: \\\"string\\\"\\n\"\nfield: \"string\"\noneOf: \"\\\"firstOne: \\\\\\\"string\\\\\\\"\\\\nsecondOne: \\\\\\\"string\\\\\\\"\\\\n\\\"\\n\"\n" ]
"examples" : [ "allOf: |\n firstOne: string\n firstTwo: 0\n secondOne: string\n secondTwo: true\nanyOf: |\n firstOne: string\n secondOne: string\nfield: string\noneOf: |\n |\n firstOne: string\n secondOne: string\n" ]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
}
},
"examples" : [ "flist:\n- b: true\n s: \"string\"\n" ]
"examples" : [ "flist:\n- b: true\n s: string\n" ]
},
"io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$SimpleFoo" : {
"type" : "string",
Expand All @@ -21,6 +21,6 @@
"type" : "string"
}
},
"examples" : [ "b: true\ns: \"string\"\n" ]
"examples" : [ "b: true\ns: string\n" ]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"type" : "string"
}
},
"examples" : [ "b: true\nd: 1.1\ndt: \"2015-07-20T15:49:04-07:00\"\nf: 1.1\ni: 0\n\"n\":\n nba: \"YmFzZTY0LWV4YW1wbGU=\"\n nc:\n cyclic: {}\n nli:\n - 0\n nmfm:\n key:\n s: \"string\"\n ns: \"string\"\n nsm:\n - s: \"string\"\n nu: \"3fa85f64-5717-4562-b3fc-2c963f66afa6\"\ns: \"string\"\n" ]
"examples" : [ "b: true\nd: 1.1\ndt: 2015-07-20T15:49:04-07:00\nf: 1.1\ni: 0\n\"n\":\n nba: YmFzZTY0LWV4YW1wbGU=\n nc:\n cyclic: {}\n nli:\n - 0\n nmfm:\n key:\n s: string\n ns: string\n nsm:\n - s: string\n nu: 3fa85f64-5717-4562-b3fc-2c963f66afa6\ns: string\n" ]
},
"io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$ComplexFoo$Nested" : {
"type" : "string",
Expand Down Expand Up @@ -68,7 +68,7 @@
"format" : "uuid"
}
},
"examples" : [ "nba: \"YmFzZTY0LWV4YW1wbGU=\"\nnc:\n cyclic: {}\nnli:\n- 0\nnmfm:\n key:\n s: \"string\"\nns: \"string\"\nnsm:\n- s: \"string\"\nnu: \"3fa85f64-5717-4562-b3fc-2c963f66afa6\"\n" ]
"examples" : [ "nba: YmFzZTY0LWV4YW1wbGU=\nnc:\n cyclic: {}\nnli:\n- 0\nnmfm:\n key:\n s: string\nns: string\nnsm:\n- s: string\nnu: 3fa85f64-5717-4562-b3fc-2c963f66afa6\n" ]
},
"io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$ComplexFoo$Nested$Cyclic" : {
"type" : "string",
Expand All @@ -86,6 +86,6 @@
"type" : "string"
}
},
"examples" : [ "s: \"string\"\n" ]
"examples" : [ "s: string\n" ]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type" : "string"
}
},
"examples" : [ "f:\n b: true\n s: \"string\"\ns: \"string\"\n" ]
"examples" : [ "f:\n b: true\n s: string\ns: string\n" ]
},
"io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$FooWithEnum" : {
"type" : "string",
Expand All @@ -22,7 +22,7 @@
"type" : "string"
}
},
"examples" : [ "b: \"BAR1\"\ns: \"string\"\n" ]
"examples" : [ "b: BAR1\ns: string\n" ]
},
"io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$SimpleFoo" : {
"type" : "string",
Expand All @@ -34,6 +34,6 @@
"type" : "string"
}
},
"examples" : [ "b: true\ns: \"string\"\n" ]
"examples" : [ "b: true\ns: string\n" ]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}
},
"description" : "foo model",
"examples" : [ "bi: 0\ndt: \"2000-01-01T02:00:00+02:00\"\nf:\n b: true\n s: \"string\"\nld: \"2024-04-24\"\nls_plain:\n- \"string\"\nmss:\n key1: \"value1\"\nmss_plain:\n key: \"string\"\ns: \"s value\"\n" ],
"examples" : [ "bi: 0\ndt: 2000-01-01T02:00:00+02:00\nf:\n b: true\n s: string\nld: 2024-04-24\nls_plain:\n- string\nmss:\n key1: value1\nmss_plain:\n key: string\ns: s value\n" ],
"required" : [ "dt", "f", "s" ]
},
"io.github.springwolf.core.asyncapi.components.DefaultYamlComponentsServiceIntegrationTest$SimpleFoo" : {
Expand All @@ -66,6 +66,6 @@
"type" : "string"
}
},
"examples" : [ "b: true\ns: \"string\"\n" ]
"examples" : [ "b: true\ns: string\n" ]
}
}
Loading

0 comments on commit 8609c89

Please sign in to comment.