Search in sources :

Example 26 with RequestBody

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());
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Content(io.swagger.v3.oas.models.media.Content) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) MediaType(io.swagger.v3.oas.models.media.MediaType) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 27 with RequestBody

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"));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Content(io.swagger.v3.oas.models.media.Content) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 28 with RequestBody

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");
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Link(io.swagger.v3.oas.models.links.Link) Test(org.testng.annotations.Test)

Example 29 with RequestBody

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;
}
Also used : lombok.val(lombok.val) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 30 with RequestBody

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();
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) PathVariable(org.springframework.web.bind.annotation.PathVariable) ActuatorMediaType(org.springframework.boot.actuate.endpoint.http.ActuatorMediaType) ZipInputStream(java.util.zip.ZipInputStream) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) StringUtils(org.apache.commons.lang3.StringUtils) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Operation(io.swagger.v3.oas.annotations.Operation) HttpServletRequest(javax.servlet.http.HttpServletRequest) ContentDisposition(org.springframework.http.ContentDisposition) ByteArrayInputStream(java.io.ByteArrayInputStream) StringSerializer(org.apereo.cas.util.serialization.StringSerializer) CollectionUtils(org.apereo.cas.util.CollectionUtils) GetMapping(org.springframework.web.bind.annotation.GetMapping) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) ServicesManager(org.apereo.cas.services.ServicesManager) Resource(org.springframework.core.io.Resource) PostMapping(org.springframework.web.bind.annotation.PostMapping) Unchecked(org.jooq.lambda.Unchecked) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) CompressionUtils(org.apereo.cas.util.CompressionUtils) IOException(java.io.IOException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RegisteredService(org.apereo.cas.services.RegisteredService) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) RestControllerEndpoint(org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) JacksonObjectMapperFactory(org.apereo.cas.util.serialization.JacksonObjectMapperFactory) NumberUtils(org.apache.commons.lang3.math.NumberUtils) ResponseEntity(org.springframework.http.ResponseEntity) ZipInputStream(java.util.zip.ZipInputStream) RegisteredService(org.apereo.cas.services.RegisteredService) ByteArrayInputStream(java.io.ByteArrayInputStream) Objects(java.util.Objects)

Aggregations

Test (org.testng.annotations.Test)67 OpenAPI (io.swagger.v3.oas.models.OpenAPI)62 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)59 Schema (io.swagger.v3.oas.models.media.Schema)46 Operation (io.swagger.v3.oas.annotations.Operation)41 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)40 MediaType (io.swagger.v3.oas.models.media.MediaType)36 StringSchema (io.swagger.v3.oas.models.media.StringSchema)35 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)32 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)32 Content (io.swagger.v3.oas.models.media.Content)31 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)28 Operation (io.swagger.v3.oas.models.Operation)27 PathItem (io.swagger.v3.oas.models.PathItem)23 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)21 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)19 Parameter (io.swagger.v3.oas.models.parameters.Parameter)15 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)14 Components (io.swagger.v3.oas.models.Components)13 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)12