Search in sources :

Example 86 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project snow-owl by b2ihealthcare.

the class FhirCodeSystemValidateCodeOperationController method validateCode.

/**
 * POST-based $validate-code end-point.
 * All parameters are in the request body
 * @param body - FHIR parameters
 * @return out - FHIR parameters
 */
@Operation(summary = "Validate a code in a code system", description = "Validate that a coded value is in a code system.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "400", description = "Bad request") })
@PostMapping(value = "/$validate-code", consumes = AbstractFhirController.APPLICATION_FHIR_JSON)
public Promise<Parameters.Fhir> validateCode(@Parameter(description = "The validate-code request parameters") @RequestBody Parameters.Fhir body) {
    final ValidateCodeRequest request = toRequest(body, ValidateCodeRequest.class);
    request.validate();
    return FhirRequests.codeSystems().prepareValidateCode().setRequest(request).buildAsync().execute(getBus()).then(this::toResponse);
}
Also used : ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 87 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project snow-owl by b2ihealthcare.

the class FhirCodeSystemSubsumesOperationController method subsumes.

/*
	 * Subsumes POST method with code system as path parameter
	 */
@Operation(summary = "Subsumption testing", description = "Test the subsumption relationship between code/Coding A and code/Coding B given the semantics of subsumption in the underlying code system (see hierarchyMeaning).")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "400", description = "Bad request") })
@PostMapping(value = "{codeSystemId:**}/$subsumes", consumes = AbstractFhirController.APPLICATION_FHIR_JSON)
public Promise<Parameters.Fhir> subsumes(@Parameter(description = "The id of the code system to invoke the operation on") @PathVariable("codeSystemId") String codeSystemId, @Parameter(description = "The lookup request parameters") @RequestBody Parameters.Fhir body) {
    SubsumptionRequest request = toRequest(body, SubsumptionRequest.class);
    validateSubsumptionRequest(request);
    // TODO: incorrect as it should use the codeSystemID instead of the systemID!
    return FhirRequests.codeSystems().prepareSubsumes().setRequest(request).buildAsync().execute(getBus()).then(this::toResponse);
}
Also used : SubsumptionRequest(com.b2international.snowowl.fhir.core.model.codesystem.SubsumptionRequest) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 88 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method testIssue343Parameter.

@Test
public void testIssue343Parameter() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + "  description: bleh\n" + "  version: 2.0.0\n" + "  title: Test\n" + "paths:\n" + "  /foo:\n" + "    post:\n" + "      parameters:\n" + "        - in: query\n" + "          name: skip\n" + "          schema:\n" + "            type: integer\n" + "            format: int32\n" + "            multipleOf: 3\n" + "      responses:\n" + "        '200':\n" + "          description: OK\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: object\n" + "              additionalProperties:\n" + "                type: string\n" + "        required: true\n" + "components:\n" + "  schemas:\n" + "    Fun:\n" + "      properties:\n" + "        id:\n" + "          type: integer\n" + "          format: int32\n" + "          multipleOf: 5\n" + "        mySet:\n" + "          type: array\n" + "          uniqueItems: true\n" + "          items:\n" + "            type: string";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    OpenAPI openAPI = result.getOpenAPI();
    QueryParameter qp = (QueryParameter) openAPI.getPaths().get("/foo").getPost().getParameters().get(0);
    assertEquals(new BigDecimal("3"), qp.getSchema().getMultipleOf());
    RequestBody bp = openAPI.getPaths().get("/foo").getPost().getRequestBody();
    Schema schema = bp.getContent().get("application/json").getSchema();
    assertTrue(schema.getAdditionalProperties() != null);
    IntegerSchema id = (IntegerSchema) openAPI.getComponents().getSchemas().get("Fun").getProperties().get("id");
    assertEquals(id.getMultipleOf(), new BigDecimal("5"));
    ArraySchema ap = (ArraySchema) openAPI.getComponents().getSchemas().get("Fun").getProperties().get("mySet");
    assertTrue(ap.getUniqueItems());
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) BinarySchema(io.swagger.v3.oas.models.media.BinarySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) BigDecimal(java.math.BigDecimal) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 89 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method testExamples.

@Test
public void testExamples(@Injectable List<AuthorizationValue> auths) {
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  title: httpbin\n" + "  version: 0.0.0\n" + "servers:\n" + "  - url: http://httpbin.org\n" + "paths:\n" + "  /post:\n" + "    post:\n" + "      summary: Returns the POSTed data\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              $ref: '#/components/schemas/AnyValue'\n" + "            examples:\n" + "              AnObject:\n" + "                $ref: '#/components/examples/AnObject'\n" + "              ANull:\n" + "                $ref: '#/components/examples/ANull'\n" + "          application/yaml:\n" + "            schema:\n" + "              $ref: '#/components/schemas/AnyValue'\n" + "            examples:\n" + "              AString:\n" + "                $ref: '#/components/examples/AString'\n" + "              AnArray:\n" + "                $ref: '#/components/examples/AnArray'\n" + "          text/plain:\n" + "            schema:\n" + "              type: string\n" + "              example: Hi there\n" + "          application/x-www-form-urlencoded:\n" + "            schema:\n" + "              type: object\n" + "              properties:\n" + "                id:\n" + "                  type: integer\n" + "                name:\n" + "                  type: string\n" + "            example:\n" + "              id: 42\n" + "              name: Arthur Dent\n" + "      responses:\n" + "        '200':\n" + "          description: OK\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                type: object\n" + "\n" + "  #/response-headers:\n" + "  /:\n" + "    get:\n" + "      summary: Returns a response with the specified headers\n" + "      parameters:\n" + "        - in: header\n" + "          name: Server\n" + "          required: true\n" + "          schema:\n" + "            type: string\n" + "          examples:\n" + "            httpbin:\n" + "              value: httpbin\n" + "            unicorn:\n" + "              value: unicorn\n" + "        - in: header\n" + "          name: X-Request-Id\n" + "          required: true\n" + "          schema:\n" + "            type: integer\n" + "          example: 37\n" + "      responses:\n" + "        '200':\n" + "          description: A response with the specified headers\n" + "          headers:\n" + "            Server:\n" + "              schema:\n" + "                type: string\n" + "              examples:\n" + "                httpbin:\n" + "                  value: httpbin\n" + "                unicorn:\n" + "                  value: unicorn\n" + "            X-Request-Id:\n" + "              schema:\n" + "                type: integer\n" + "              example: 37\n" + "\n" + "components:\n" + "  schemas:\n" + "    AnyValue:\n" + "      nullable: true\n" + "      description: Can be anything - string, object, array, null, etc.\n" + "\n" + "  examples:\n" + "    AString:\n" + "      value: Hi there\n" + "    ANumber:\n" + "      value: 42\n" + "    ANull:\n" + "      value: null\n" + "    AnArray:\n" + "      value: [1, 2, 3]\n" + "    AnObject:\n" + "      value:\n" + "        id:  42\n" + "        name: Arthur Dent";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = parser.readContents(yaml, auths, options);
    OpenAPI openAPI = result.getOpenAPI();
    MediaType mediaTypeJson = openAPI.getPaths().get("/post").getPost().getRequestBody().getContent().get("application/json");
    Header header1 = openAPI.getPaths().get("/").getGet().getResponses().get("200").getHeaders().get("Server");
    Header header2 = openAPI.getPaths().get("/").getGet().getResponses().get("200").getHeaders().get("X-Request-Id");
    Parameter parameter1 = openAPI.getPaths().get("/").getGet().getParameters().get(0);
    Parameter parameter2 = openAPI.getPaths().get("/").getGet().getParameters().get(1);
    Assert.assertNotNull(mediaTypeJson.getExamples());
    Assert.assertEquals(mediaTypeJson.getExamples().get("AnObject").get$ref(), "#/components/examples/AnObject");
    Assert.assertNotNull(header1.getExamples());
    Assert.assertEquals(header1.getExamples().get("httpbin").getValue(), "httpbin");
    Assert.assertNotNull(header2.getExample());
    Assert.assertEquals(header2.getExample(), 37);
    Assert.assertNotNull(parameter1.getExamples());
    Assert.assertEquals(parameter1.getExamples().get("unicorn").getValue(), "unicorn");
    Assert.assertNotNull(parameter2.getExample());
    Assert.assertEquals(parameter2.getExample(), 37);
}
Also used : Header(io.swagger.v3.oas.models.headers.Header) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) MediaType(io.swagger.v3.oas.models.media.MediaType) Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 90 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method propertyTest.

@Test
public void propertyTest(@Injectable List<AuthorizationValue> auths) {
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /primitiveBody/inline:\n" + "    post:\n" + "      x-swagger-router-controller: TestController\n" + "      operationId: inlineRequiredBody\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: object\n" + "              properties:\n" + "                name:\n" + "                  type: string\n" + "        required: true\n" + "      responses:\n" + "        '200':\n" + "          description: ok!";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = parser.readContents(yaml, auths, options);
    OpenAPI openAPI = result.getOpenAPI();
    Map<String, Schema> properties = openAPI.getPaths().get("/primitiveBody/inline").getPost().getRequestBody().getContent().get("application/json").getSchema().getProperties();
    assertTrue(properties.get("name") instanceof StringSchema);
}
Also used : DateSchema(io.swagger.v3.oas.models.media.DateSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) BinarySchema(io.swagger.v3.oas.models.media.BinarySchema) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) StringSchema(io.swagger.v3.oas.models.media.StringSchema) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

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