use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class FileReferenceTest method testIssue340.
@Test
public void testIssue340() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/nested-file-references/issue-340.json", null, options);
assertNotNull(result.getOpenAPI());
OpenAPI swagger = result.getOpenAPI();
assertFalse(swagger.getComponents().getSchemas().get("BarData").get$ref() != null);
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testOneOfSchema.
@Test
public void testOneOfSchema(@Injectable List<AuthorizationValue> auths) {
String yaml = "openapi: '3.0'\n" + "components:\n" + " schemas:\n" + " Cat:\n" + " type: object\n" + " # all properties specific to a `Cat`\n" + " properties:\n" + " purring:\n" + " type: string\n" + " Dog:\n" + " type: object\n" + " # all properties specific to a `Dog`\n" + " properties:\n" + " bark:\n" + " type: string\n" + " Pet:\n" + " oneOf: \n" + " - $ref: '#/components/schemas/Cat'\n" + " - $ref: '#/components/schemas/Dog'\n" + " - type: object\n" + " # neither a `Cat` nor a `Dog`\n" + " properties:\n" + " name:\n" + " type: string\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 petSchema = result.getOpenAPI().getComponents().getSchemas().get("Pet");
assertTrue(petSchema != null);
assertTrue(petSchema instanceof ComposedSchema);
ComposedSchema petCompSchema = (ComposedSchema) petSchema;
List<Schema> oneOfSchemas = petCompSchema.getOneOf();
assertTrue(oneOfSchemas != null);
assertEquals(oneOfSchemas.size(), 3);
Schema refCatSchema = oneOfSchemas.get(0);
assertTrue(refCatSchema != null);
assertEquals(refCatSchema.get$ref(), "#/components/schemas/Cat");
Schema refDogSchema = oneOfSchemas.get(1);
assertTrue(refDogSchema != null);
assertEquals(refDogSchema.get$ref(), "#/components/schemas/Dog");
Schema otherSchema = oneOfSchemas.get(2);
assertTrue(otherSchema != null);
Schema nameProp = (Schema) otherSchema.getProperties().get("name");
assertTrue(nameProp != null);
assertEquals(nameProp.getType(), "string");
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testEnumType.
@Test
public void testEnumType() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/issue-1090.yaml", null, options);
assertNotNull(result.getOpenAPI());
OpenAPI openAPI = result.getOpenAPI();
Schema someObj = openAPI.getComponents().getSchemas().get("SomeObj");
assertNotNull(someObj);
Map<String, Schema> properties = someObj.getProperties();
assertNotNull(properties);
Schema iprop = properties.get("iprop");
assertNotNull(iprop);
assertEquals(iprop.getType(), "integer");
assertEquals(iprop.getFormat(), "int32");
Schema lprop = properties.get("lprop");
assertNotNull(lprop);
assertEquals(lprop.getType(), "integer");
assertEquals(lprop.getFormat(), "int64");
Schema nprop = properties.get("nprop");
assertNotNull(nprop);
assertEquals(nprop.getType(), "number");
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testAlmostEmpty.
@Test
public void testAlmostEmpty(@Injectable List<AuthorizationValue> auths) {
String yaml = "openapi: '3.0.1'\n" + "new: extra";
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);
assertTrue(messages.contains("attribute info is missing"));
assertTrue(messages.contains("attribute paths is missing"));
assertTrue(messages.contains("attribute new is unexpected"));
}
use of io.swagger.v3.parser.core.models.ParseOptions 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");
}
Aggregations