use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArbitraryObjectBodyParamWithArray.
@Test
public void testArbitraryObjectBodyParamWithArray() {
OpenAPI openAPI = new OpenAPI();
openAPI.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(new ArraySchema().items(new ObjectSchema())))))));
new InlineModelResolver().flatten(openAPI);
RequestBody requestBody = openAPI.getPaths().get("/hello").getGet().getRequestBody();
Schema schema = requestBody.getContent().get("*/*").getSchema();
assertTrue(schema instanceof ArraySchema);
ArraySchema arraySchema = (ArraySchema) schema;
Schema inner = arraySchema.getItems();
assertTrue(inner instanceof ObjectSchema);
ObjectSchema property = (ObjectSchema) inner;
assertNotNull(property);
assertNull(property.getProperties());
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class InlineModelResolverTest method resolveInlineRequestBody_stripsDotsFromPath.
@Test
public void resolveInlineRequestBody_stripsDotsFromPath() throws Exception {
OpenAPI openAPI = new OpenAPI();
ObjectSchema objectSchema = new ObjectSchema();
objectSchema.addProperties("street", new StringSchema());
Schema schema = new Schema();
schema.addProperties("address", objectSchema);
schema.addProperties("name", new StringSchema());
MediaType mediaType = new MediaType();
mediaType.setSchema(schema);
Content content = new Content();
content.addMediaType("*/*", mediaType);
RequestBody requestBody = new RequestBody();
requestBody.setContent(content);
Operation operation = new Operation();
operation.setRequestBody(requestBody);
PathItem pathItem = new PathItem();
pathItem.setGet(operation);
openAPI.path("/api/Cloud.Greet.Hello", pathItem);
new InlineModelResolver(true, true).flatten(openAPI);
Operation getOperation = openAPI.getPaths().get("/api/Cloud.Greet.Hello").getGet();
RequestBody body = getOperation.getRequestBody();
assertEquals("use dot as common word separator: as it occurs frequently on OData services", "#/components/schemas/ApiCloudGreetHelloBody", body.getContent().get("*/*").getSchema().get$ref());
Schema bodySchema = openAPI.getComponents().getSchemas().get("ApiCloudGreetHelloBody");
assertTrue(bodySchema instanceof Schema);
assertNotNull(bodySchema.getProperties().get("address"));
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testRemotePathItemIssue1103.
@Test
public void testRemotePathItemIssue1103(@Injectable final List<AuthorizationValue> auths) throws Exception {
OpenAPI result = new OpenAPIV3Parser().read("issue-1103/remote-pathItem-swagger.yaml");
Assert.assertNotNull(result);
Assert.assertNotNull(result.getPaths().get("/Translation/{lang}"));
Assert.assertEquals(result.getPaths().get("/Translation/{lang}").getPut().getParameters().get(0).getName(), "lang");
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method doRelativeFileTest.
private OpenAPI doRelativeFileTest(String location) {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult readResult = parser.readLocation(location, null, options);
if (readResult.getMessages().size() > 0) {
Json.prettyPrint(readResult.getMessages());
}
final OpenAPI openAPI = readResult.getOpenAPI();
final PathItem path = openAPI.getPaths().get("/health");
// we successfully converted the RefPath to a Path
assertEquals(path.getClass(), PathItem.class);
final List<Parameter> parameters = path.getParameters();
assertParamDetails(parameters, 0, QueryParameter.class, "param1", "query");
assertParamDetails(parameters, 1, HeaderParameter.class, "param2", "header");
final Operation operation = path.getGet();
final List<Parameter> operationParams = operation.getParameters();
assertParamDetails(operationParams, 0, PathParameter.class, "param3", "path");
assertParamDetails(operationParams, 1, HeaderParameter.class, "param4", "header");
final Map<String, ApiResponse> responsesMap = operation.getResponses();
assertResponse(openAPI, responsesMap, "200", "application/json", "Health information from the server", "#/components/schemas/health");
assertResponse(openAPI, responsesMap, "400", "*/*", "Your request was not valid", "#/components/schemas/error");
assertResponse(openAPI, responsesMap, "500", "*/*", "An unexpected error occur during processing", "#/components/schemas/error");
final Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
final Schema refInDefinitions = definitions.get("refInDefinitions");
assertEquals(refInDefinitions.getDescription(), "The example model");
expectedPropertiesInModel(refInDefinitions, "foo", "bar");
final ArraySchema arrayModel = (ArraySchema) definitions.get("arrayModel");
final Schema arrayModelItems = arrayModel.getItems();
assertEquals(arrayModelItems.get$ref(), "#/components/schemas/foo");
final Schema fooModel = definitions.get("foo");
assertEquals(fooModel.getDescription(), "Just another model");
expectedPropertiesInModel(fooModel, "hello", "world");
final ComposedSchema composedCat = (ComposedSchema) definitions.get("composedCat");
final Schema child = composedCat.getAllOf().get(2);
expectedPropertiesInModel(child, "huntingSkill", "prop2", "reflexes", "reflexMap");
final ArraySchema reflexes = (ArraySchema) child.getProperties().get("reflexes");
final Schema reflexItems = reflexes.getItems();
assertEquals(reflexItems.get$ref(), "#/components/schemas/reflex");
assertTrue(definitions.containsKey(reflexItems.get$ref().substring(reflexItems.get$ref().lastIndexOf("/") + 1)));
final Schema reflexMap = (Schema) child.getProperties().get("reflexMap");
final Schema reflexMapAdditionalProperties = (Schema) reflexMap.getAdditionalProperties();
assertEquals(reflexMapAdditionalProperties.get$ref(), "#/components/schemas/reflex");
assertEquals(composedCat.getAllOf().size(), 3);
assertEquals(composedCat.getAllOf().get(0).get$ref(), "#/components/schemas/pet");
assertEquals(composedCat.getAllOf().get(1).get$ref(), "#/components/schemas/foo_1");
return openAPI;
}
use of io.swagger.v3.oas.models.PathItem in project swagger-core by swagger-api.
the class JsonDeserializationTest method testDeserializeAPathRef.
@Test
public void testDeserializeAPathRef() throws Exception {
final OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/pathRef.json", OpenAPI.class);
final PathItem petPath = oas.getPaths().get("/pet");
assertNotNull(petPath.get$ref());
assertEquals(petPath.get$ref(), "http://my.company.com/paths/health.json");
assertTrue(oas.getPaths().get("/user") instanceof PathItem);
}
Aggregations