use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testEmpty.
@Test
public void testEmpty() {
String json = "{}";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(json, null, null);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<>(messageList);
assertTrue(messages.contains("attribute openapi is missing"));
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testAnyOfSchema.
@Test
public void testAnyOfSchema(@Injectable List<AuthorizationValue> auths) {
String yaml = "openapi: '3.0'\n" + "components:\n" + " schemas:\n" + " id:\n" + " anyOf: \n" + " - type: string\n" + " - type: number\n";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readContents(yaml, auths, options);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<>(messageList);
Schema idSchema = result.getOpenAPI().getComponents().getSchemas().get("id");
assertTrue(idSchema != null);
assertTrue(idSchema instanceof ComposedSchema);
ComposedSchema idCompSchema = (ComposedSchema) idSchema;
List<Schema> anyOfSchemas = idCompSchema.getAnyOf();
assertTrue(anyOfSchemas != null);
assertEquals(anyOfSchemas.size(), 2);
Schema stringSchema = anyOfSchemas.get(0);
assertTrue(stringSchema != null);
assertEquals(stringSchema.getType(), "string");
Schema numberSchema = anyOfSchemas.get(1);
assertTrue(numberSchema != null);
assertEquals(numberSchema.getType(), "number");
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testLicense.
@Test
public void testLicense() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " license:\n" + " invalid: true\n" + " x-valid:\n" + " isValid: true\n" + " version: ''\n";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<>(messageList);
assertTrue(messages.contains("attribute info.license.invalid is unexpected"));
assertTrue(messages.contains("attribute info.title is missing"));
assertTrue(messages.contains("attribute paths is missing"));
assertEquals(((Map) result.getOpenAPI().getInfo().getLicense().getExtensions().get("x-valid")).get("isValid"), true);
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testResponses.
@Test
public void testResponses() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " version: ''\n" + " title: ''\n" + "paths: {}\n" + "components:\n" + " responses:\n" + " foo:\n" + " description: description\n" + " bar: baz\n" + " x-foo: bar";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<>(messageList);
assertTrue(messages.contains("attribute components.responses.foo.bar is unexpected"));
assertEquals(result.getOpenAPI().getComponents().getResponses().get("foo").getExtensions().get("x-foo").toString(), "bar");
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testDiscriminatorObject.
@Test
void testDiscriminatorObject(@Injectable List<AuthorizationValue> auths) {
String yaml = "openapi: '3.0.1'\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " type: object\n" + " required:\n" + " - pet_type\n" + " properties:\n" + " pet_type:\n" + " type: string\n" + " discriminator:\n" + " propertyName: pet_type\n" + " mapping:\n" + " cachorro: Dog\n" + " Cat:\n" + " allOf:\n" + " - $ref: '#/components/schemas/Pet'\n" + " - type: object\n" + " # all other properties specific to a `Cat`\n" + " properties:\n" + " name:\n" + " type: string\n" + " Dog:\n" + " allOf:\n" + " - $ref: '#/components/schemas/Pet'\n" + " - type: object\n" + " # all other properties specific to a `Dog`\n" + " properties:\n" + " bark:\n" + " type: string\n" + " Lizard:\n" + " allOf:\n" + " - $ref: '#/components/schemas/Pet'\n" + " - type: object\n" + " # all other properties specific to a `Lizard`\n" + " properties:\n" + " lovesRocks:\n" + " type: boolean";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readContents(yaml, auths, options);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<>(messageList);
assertEquals(result.getOpenAPI().getComponents().getSchemas().get("Pet").getDiscriminator().getPropertyName(), "pet_type");
assertEquals(result.getOpenAPI().getComponents().getSchemas().get("Pet").getDiscriminator().getMapping().get("cachorro"), "Dog");
assertTrue(messages.contains("attribute paths is missing"));
assertTrue(messages.contains("attribute info is missing"));
}
Aggregations