use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArbitraryObjectRequestBodyInline.
@Test
public void testArbitraryObjectRequestBodyInline() {
OpenAPI swagger = new OpenAPI();
Schema schema = new Schema();
schema.addProperties("arbitrary", new ObjectSchema());
swagger.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(schema))))));
new InlineModelResolver().flatten(swagger);
Operation operation = swagger.getPaths().get("/hello").getGet();
RequestBody requestBody = operation.getRequestBody();
assertTrue(requestBody.getContent().get("*/*").getSchema().get$ref() != null);
Schema body = swagger.getComponents().getSchemas().get("hello_body");
assertTrue(body instanceof Schema);
Schema property = (Schema) body.getProperties().get("arbitrary");
assertNotNull(property);
assertTrue(property instanceof ObjectSchema);
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testSkipInlineMatchesTrue.
@Test
public void testSkipInlineMatchesTrue() {
final OpenAPI openAPI = new OpenAPI();
final InlineModelResolver inlineModelResolver = new InlineModelResolver(false, false, true);
final Schema operationAlphaInAsset = new ObjectSchema();
operationAlphaInAsset.setTitle("operationAlphaInAsset");
operationAlphaInAsset.addProperties("id1", new IntegerSchema());
operationAlphaInAsset.addProperties("id2", new IntegerSchema());
final Schema operationAlphaIn = new ObjectSchema();
operationAlphaIn.setTitle("operationAlphaIn");
operationAlphaIn.addProperties("asset", operationAlphaInAsset);
final Schema operationAlphaRequest = new ObjectSchema();
operationAlphaRequest.setTitle("operationAlphaRequest");
operationAlphaRequest.addProperties("in", operationAlphaIn);
final Schema operationBetaInAsset = new ObjectSchema();
operationBetaInAsset.setTitle("operationBetaInAsset");
operationBetaInAsset.addProperties("id1", new IntegerSchema());
operationBetaInAsset.addProperties("id2", new IntegerSchema());
final Schema operationBetaIn = new ObjectSchema();
operationBetaIn.setTitle("operationBetaIn");
operationBetaIn.addProperties("asset", operationBetaInAsset);
final Schema operationBetaRequest = new ObjectSchema();
operationBetaRequest.setTitle("operationBetaRequest");
operationBetaRequest.addProperties("in", operationBetaIn);
openAPI.path("/operationAlpha", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(operationAlphaRequest))))));
openAPI.path("/operationBeta", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(operationBetaRequest))))));
inlineModelResolver.flatten(openAPI);
assertNotNull(openAPI);
assertNotNull(openAPI.getComponents());
assertNotNull(openAPI.getComponents().getSchemas());
assertEquals(6, openAPI.getComponents().getSchemas().size());
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArbitraryObjectResponseMapInline.
@Test
public void testArbitraryObjectResponseMapInline() {
OpenAPI openAPI = new OpenAPI();
Schema schema = new Schema();
schema.setAdditionalProperties(new ObjectSchema());
openAPI.path("/foo/baz", new PathItem().get(new Operation().responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("it works!").content(new Content().addMediaType("*/*", new MediaType().schema(schema)))))));
new InlineModelResolver().flatten(openAPI);
ApiResponse response = openAPI.getPaths().get("/foo/baz").getGet().getResponses().get("200");
Schema property = response.getContent().get("*/*").getSchema();
assertTrue(property.getAdditionalProperties() != null);
assertTrue(property.getAdditionalProperties() instanceof Schema);
assertTrue(openAPI.getComponents().getSchemas() == null);
Schema inlineProp = (Schema) property.getAdditionalProperties();
assertTrue(inlineProp instanceof ObjectSchema);
ObjectSchema op = (ObjectSchema) inlineProp;
assertNull(op.getProperties());
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class InlineModelResolverTest method resolveInlineRequestBodyWithTitle.
@Test
public void resolveInlineRequestBodyWithTitle() throws Exception {
OpenAPI openAPI = new OpenAPI();
ObjectSchema objectSchema = new ObjectSchema();
objectSchema.addProperties("street", new StringSchema());
objectSchema.addProperties("name", new StringSchema());
Schema addressModelItem = new Schema();
String addressModelName = "DetailedAddress";
addressModelItem.setTitle(addressModelName);
addressModelItem.addProperties("address", objectSchema);
openAPI.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(addressModelItem))))));
new InlineModelResolver().flatten(openAPI);
Operation operation = openAPI.getPaths().get("/hello").getGet();
RequestBody requestBody = operation.getRequestBody();
assertTrue(requestBody.getContent().get("*/*").getSchema().get$ref() != null);
Schema body = openAPI.getComponents().getSchemas().get(addressModelName);
assertTrue(body instanceof Schema);
assertNotNull(body.getProperties().get("address"));
}
use of io.swagger.v3.oas.models.PathItem in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readExamplesObject.
@Test(dataProvider = "data")
public void readExamplesObject(JsonNode rootNode) throws Exception {
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
final Paths paths = openAPI.getPaths();
Assert.assertNotNull(paths);
Assert.assertEquals(paths.size(), 19);
// parameters operation get
PathItem petByStatusEndpoint = paths.get("/pet/findByStatus");
Assert.assertNotNull(petByStatusEndpoint.getGet());
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().size(), 1);
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getName(), "status");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getIn(), "query");
}
Aggregations