use of io.swagger.v3.oas.annotations.parameters.RequestBody 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.annotations.parameters.RequestBody 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.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testLinkIssue.
@Test
public void testLinkIssue() {
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/linkIssue.yaml", null, parseOptions);
Map<String, Link> links = openAPI.getPaths().get("/2.0/repositories/{username}").getGet().getResponses().get("200").getLinks();
Object requestBody = links.get("userRepository").getRequestBody();
assertEquals(requestBody, "$response.body#/slug");
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project cas by apereo.
the class AttributeConsentReportEndpoint method importAccount.
/**
* Import account.
*
* @param request the request
* @return the http status
* @throws Exception the exception
*/
@PostMapping(path = "/import", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Import a consent decision as a JSON document")
public HttpStatus importAccount(final HttpServletRequest request) throws Exception {
val requestBody = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
LOGGER.trace("Submitted account: [{}]", requestBody);
val decision = MAPPER.readValue(requestBody, new TypeReference<ConsentDecision>() {
});
LOGGER.trace("Storing account: [{}]", decision);
consentRepository.getObject().storeConsentDecision(decision);
return HttpStatus.CREATED;
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project cas by apereo.
the class RegisteredServicesEndpoint method importServicesAsStream.
private ResponseEntity<RegisteredService> importServicesAsStream(final HttpServletRequest request) throws IOException {
var servicesToImport = Stream.<RegisteredService>empty();
try (val bais = new ByteArrayInputStream(IOUtils.toByteArray(request.getInputStream()));
val zipIn = new ZipInputStream(bais)) {
var entry = zipIn.getNextEntry();
while (entry != null) {
if (!entry.isDirectory()) {
val requestBody = IOUtils.toString(zipIn, StandardCharsets.UTF_8);
servicesToImport = Stream.concat(servicesToImport, registeredServiceSerializers.stream().map(serializer -> serializer.from(requestBody)).filter(Objects::nonNull));
}
zipIn.closeEntry();
entry = zipIn.getNextEntry();
}
}
servicesManager.save(servicesToImport);
return ResponseEntity.ok().build();
}
Aggregations