-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ExampleJsonGenerator and Support XML Examples (#581)
* test(examples): trim all expect asyncapi specs before comparison * feat(core): pass content type to example generator * refactor(core): rename ExampleGenerator to SchemaWalker * WIP First xml exmaple working * WIP XML * WIP XML * All tests green * refactor and fix map schema * chore(core): Fixes after rebase, fix special cases * chore(core): use in kafka example * feat(core): generated examples are either of type JsonNode for Json oder String for XML examples, ExampleJsonValueGenerator caches already generated examples and reuses them when needed * chore(core): cleanup ToDos, fix tests * chore(core): adapt new implementation for generating examples to changes implementation for allOf after rebase * refactor(core): rename Default*SchemasServiceTests to Default*ComponentsServiceTest, extracted tests that do not cover serialization to DefaultComponentsServiceTest from Default*ComponentsServiceTest to remove duplication * refactor(core): removed combineObjectExample() from ExampleValueGenerator because it duplicates createObjectExample() * refactor(core): properly specify version of jakarta.validation-api dependency * chore(core): Removed TODO to throw exception for some schema types * refactor(core): parse example string to xml node in ExampleXmlValueGenerator * refactor(core): extract ExampleXmlValueSerializer to enable custom serialization configurations for xml examples * fix(examples): fix asyncapi.json for the amqp-example * fix(examples): fix asyncapi.json for the sqs-example * fix(examples): fix asyncapi.json for the jms-example * fix(examples): fix asyncapi.json for the kafka-example * refactor(core): moves methods and add class comments * chore(core): add org.slf4j:slf4j-simple to version management * feat(core): Add support for examples in YAML format * chore(core): cleanup test setup in DefaultJsonComponentsServiceTest and DefaultXmlComponentsServiceTest * chore(kafka-example): add example for schema with with examples in yaml format * refactor(core): unify method names of ExampleValueGenerator interface * refactor(core): remove debug log from ExampleXmlValueGenerator * chore(ui): add temporary fix for spec validation of other content types than json * chore(core): unify naming of internal methods of DefaultSchemaWalker.java, add sorting for all properties in examples Co-authored-by: Timon Back <[email protected]> * chore(ui): document github issue about non json payload in examples Co-authored-by: Timon Back <[email protected]> * refactor(core): minimal serialization configuration for DefaultExampleXmlValueSerializer Co-authored-by: Timon Back <[email protected]> * chore(core): cleanup deprecations Co-authored-by: Timon Back <[email protected]> * chore(kafka-example): fix operation description Co-authored-by: Timon Back <[email protected]> --------- Co-authored-by: Timon Back <[email protected]>
- Loading branch information
Showing
84 changed files
with
4,363 additions
and
822 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ava/io/github/stavshamir/springwolf/schemas/example/DefaultExampleXmlValueSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.schemas.example; | ||
|
||
import org.w3c.dom.Document; | ||
|
||
import javax.xml.transform.OutputKeys; | ||
import javax.xml.transform.Transformer; | ||
import javax.xml.transform.TransformerException; | ||
import javax.xml.transform.TransformerFactory; | ||
import javax.xml.transform.dom.DOMSource; | ||
import javax.xml.transform.stream.StreamResult; | ||
|
||
import java.io.StringWriter; | ||
|
||
public class DefaultExampleXmlValueSerializer implements ExampleXmlValueSerializer { | ||
@Override | ||
public String writeDocumentAsXmlString(Document document) throws TransformerException { | ||
DOMSource domSource = new DOMSource(document); | ||
Transformer transformer = TransformerFactory.newInstance().newTransformer(); | ||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); | ||
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); | ||
transformer.setOutputProperty(OutputKeys.INDENT, "no"); | ||
StringWriter sw = new StringWriter(); | ||
StreamResult sr = new StreamResult(sw); | ||
transformer.transform(domSource, sr); | ||
return sw.toString(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...va/io/github/stavshamir/springwolf/schemas/example/DefaultExampleYamlValueSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.schemas.example; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.swagger.v3.core.util.Yaml; | ||
|
||
public class DefaultExampleYamlValueSerializer implements ExampleYamlValueSerializer { | ||
|
||
private static final ObjectMapper yamlMapper = Yaml.mapper(); | ||
|
||
@Override | ||
public String writeDocumentAsYamlString(JsonNode node) throws JsonProcessingException { | ||
return yamlMapper.writeValueAsString(node); | ||
} | ||
} |
Oops, something went wrong.