use of io.swagger.v3.parser.core.models.ParseOptions 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"));
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssue768.
@Test
public void testIssue768() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIParser().readLocation("issue768-main.yaml", null, options);
assertNotNull(result);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);
Components components = openAPI.getComponents();
assertNotNull(components);
Map<String, Schema> schemas = components.getSchemas();
assertNotNull(schemas);
assertEquals(schemas.size(), 1);
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssue258.
@Test
public void testIssue258() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIParser().readLocation("duplicateOperationId.json", null, options);
System.out.println(result.getMessages());
assertNotNull(result);
assertNotNull(result.getOpenAPI());
assertEquals(result.getMessages().get(0), "attribute paths.'/pets/{id}'(post).operationId is repeated");
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssue1143.
@Test
public void testIssue1143() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIParser().readLocation("issue-1143.json", null, options);
assertNotNull(result.getOpenAPI());
assertNotNull(result.getOpenAPI().getComponents().getSchemas().get("RedisResource"));
assertNotNull(result.getOpenAPI().getComponents().getSchemas().get("identificacion_usuario_aplicacion"));
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssueRelativeRefs2.
@Test
public void testIssueRelativeRefs2() {
String location = "exampleSpecs/specs/my-domain/test-api/v1/test-api-swagger_v1.json";
ParseOptions po = new ParseOptions();
po.setResolve(true);
SwaggerParseResult result = new OpenAPIParser().readLocation(location, null, po);
assertNotNull(result.getOpenAPI());
OpenAPI openAPI = result.getOpenAPI();
Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
Assert.assertTrue(schemas.get("confirmMessageType_v01").getProperties().get("resources") instanceof ArraySchema);
ArraySchema arraySchema = (ArraySchema) schemas.get("confirmMessageType_v01").getProperties().get("resources");
Schema prop = (Schema) arraySchema.getItems().getProperties().get("resourceID");
assertEquals(prop.get$ref(), "#/components/schemas/simpleIDType_v01");
}
Aggregations