use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class ReaderTest method testExampleWithRef.
@Test(description = "Example with ref")
public void testExampleWithRef() {
Components components = new Components();
components.addExamples("Id", new Example().description("Id Example").summary("Id Example").value("1"));
OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(RefExamplesResource.class);
String yaml = "openapi: 3.0.1\n" + "info:\n" + " description: info\n" + "paths:\n" + " /example:\n" + " post:\n" + " description: subscribes a client to updates relevant to the requestor's account\n" + " operationId: subscribe\n" + " parameters:\n" + " - name: subscriptionId\n" + " in: path\n" + " required: true\n" + " style: simple\n" + " schema:\n" + " type: string\n" + " description: Schema\n" + " example: Subscription example\n" + " examples:\n" + " subscriptionId_1:\n" + " summary: Subscription number 12345\n" + " description: subscriptionId_1\n" + " value: 12345\n" + " externalValue: Subscription external value 1\n" + " $ref: '#/components/examples/Id'\n" + " example: example\n" + " requestBody:\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " type: integer\n" + " format: int32\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/SubscriptionResponse'\n" + "components:\n" + " schemas:\n" + " SubscriptionResponse:\n" + " type: object\n" + " properties:\n" + " subscriptionId:\n" + " type: string\n" + " examples:\n" + " Id:\n" + " summary: Id Example\n" + " description: Id Example\n" + " value: \"1\"\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class ASwaggerMavenIntegrationTest method runTest.
SwaggerMojo runTest(File pom, Consumer<OpenAPI> validator) throws Exception {
assertNotNull(pom);
assertTrue(pom.exists());
SwaggerMojo swaggerMojo = (SwaggerMojo) lookupConfiguredMojo(pom, "resolve");
// set random context id to not mix states with multiple tests
swaggerMojo.setContextId(RandomStringUtils.randomAscii(32));
assertNotNull(swaggerMojo);
swaggerMojo.execute();
final PlexusConfiguration config = extractPluginConfiguration("swagger-maven-plugin", pom);
String outputPath = swaggerMojo.getOutputPath();
String outputFile = config.getChild("outputFileName").getValue();
if (outputFile == null) {
outputFile = "openapi";
}
String format = config.getChild("outputFormat").getValue();
if (format.toLowerCase().equals("yaml") || format.toLowerCase().equals("jsonandyaml")) {
Path path = Paths.get(outputPath, outputFile + ".yaml");
File file = path.toFile();
assertTrue(Files.isRegularFile(path));
String content = FileUtils.readFileToString(file, "UTF-8");
final OpenAPI openAPI = Yaml.mapper().readValue(content, OpenAPI.class);
assertNotNull(openAPI);
validator.accept(openAPI);
}
if (format.toLowerCase().equals("json") || format.toLowerCase().equals("jsonandyaml")) {
Path path = Paths.get(outputPath, outputFile + ".json");
File file = path.toFile();
assertTrue(Files.isRegularFile(path));
String content = FileUtils.readFileToString(file, "UTF-8");
final OpenAPI openAPI = Json.mapper().readValue(content, OpenAPI.class);
assertNotNull(openAPI);
validator.accept(openAPI);
}
return swaggerMojo;
}
Aggregations