Search in sources :

Example 26 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.

the class ParameterSerializationTest method serializeHeaderParameter.

@Test(description = "it should it should serialize a HeaderParameter")
public void serializeHeaderParameter() {
    final Parameter p = new HeaderParameter().schema(new StringSchema());
    final String json = "{\"in\":\"header\",\"schema\":{\"type\":\"string\"}}";
    SerializationMatchers.assertEqualsToJson(p, json);
    final String yaml = "---\n" + "in: \"header\"\n" + "schema:\n" + "  type: \"string\"";
    SerializationMatchers.assertEqualsToYaml(p, yaml);
}
Also used : Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) StringSchema(io.swagger.v3.oas.models.media.StringSchema) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 27 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.

the class ParameterSerializationTest method serializeStringArrayHeaderParameter.

@Test(description = "it should serialize a string array HeaderParameter")
public void serializeStringArrayHeaderParameter() {
    final Parameter p = new HeaderParameter().schema(new ArraySchema().items(new StringSchema()));
    final String json = "{\"in\":\"header\",\"schema\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}";
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) StringSchema(io.swagger.v3.oas.models.media.StringSchema) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 28 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.

the class ReaderTest method testParameterWithRef.

@Test(description = "Parameter with ref")
public void testParameterWithRef() {
    Components components = new Components();
    components.addParameters("id", new Parameter().description("Id Description").schema(new IntegerSchema()).in(ParameterIn.QUERY.toString()).example(1).required(true));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(RefParameterResource.class);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      summary: Simple get operation\n" + "      description: Defines a simple get operation with a payload complex input object\n" + "      operationId: sendPayload\n" + "      parameters:\n" + "      - $ref: '#/components/parameters/id'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "      deprecated: true\n" + "components:\n" + "  parameters: \n" + "    id:\n" + "      in: query\n" + "      description: Id Description\n" + "      required: true\n" + "      schema:\n" + "        type: integer\n" + "        format: int32\n" + "      example: 1\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 29 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.

the class ReaderTest method testTicket3587.

@Test(description = "Parameter examples ordering")
public void testTicket3587() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket3587Resource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /test/test:\n" + "    get:\n" + "      operationId: parameterExamplesOrderingTest\n" + "      parameters:\n" + "      - in: query\n" + "        schema:\n" + "          type: string\n" + "        examples:\n" + "          Example One:\n" + "            description: Example One\n" + "          Example Two:\n" + "            description: Example Two\n" + "          Example Three:\n" + "            description: Example Three\n" + "      - in: query\n" + "        schema:\n" + "          type: string\n" + "        examples:\n" + "          Example Three:\n" + "            description: Example Three\n" + "          Example Two:\n" + "            description: Example Two\n" + "          Example One:\n" + "            description: Example One\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}";
    SerializationMatchers.assertEqualsToYamlExact(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 30 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.

the class ReaderTest method testSubscriptionIdParam.

@Test(description = "Get the Param of an operation")
public void testSubscriptionIdParam() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(BasicFieldsResource.class);
    assertNotNull(openAPI);
    Paths openAPIPaths = openAPI.getPaths();
    assertNotNull(openAPIPaths);
    PathItem pathItem = openAPIPaths.get(PATH_1_REF);
    assertNotNull(pathItem);
    Operation operation = pathItem.getGet();
    assertNotNull(operation);
    List<Parameter> parameters = operation.getParameters();
    assertNotNull(parameters);
    assertEquals(PARAMETER_NUMBER, parameters.size());
    Parameter parameter = parameters.get(0);
    assertNotNull(parameter);
    assertEquals(PARAMETER_IN, parameter.getIn());
    assertEquals(PARAMETER_NAME, parameter.getName());
    assertEquals(PARAMETER_DESCRIPTION, parameter.getDescription());
    assertEquals(Boolean.TRUE, parameter.getRequired());
    assertEquals(Boolean.TRUE, parameter.getAllowEmptyValue());
    assertEquals(Boolean.TRUE, parameter.getAllowReserved());
    Schema schema = parameter.getSchema();
    assertNotNull(schema);
    assertEquals(SCHEMA_TYPE, schema.getType());
    assertEquals(SCHEMA_FORMAT, schema.getFormat());
    assertEquals(SCHEMA_DESCRIPTION, schema.getDescription());
    assertEquals(Boolean.TRUE, schema.getReadOnly());
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Paths(io.swagger.v3.oas.models.Paths) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)59 Parameter (io.swagger.v3.oas.models.parameters.Parameter)48 Test (org.testng.annotations.Test)39 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)33 Operation (io.swagger.v3.oas.models.Operation)28 lombok.val (lombok.val)26 OpenAPI (io.swagger.v3.oas.models.OpenAPI)20 Map (java.util.Map)18 ArrayList (java.util.ArrayList)16 ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)15 OpenAPI3RequestValidationHandlerImpl (io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl)14 Test (org.junit.Test)14 PathItem (io.swagger.v3.oas.models.PathItem)13 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)13 StringUtils (org.apache.commons.lang3.StringUtils)13 Parameter (io.swagger.v3.oas.annotations.Parameter)12 StringSchema (io.swagger.v3.oas.models.media.StringSchema)12 LinkedHashMap (java.util.LinkedHashMap)12 RequestParameters (io.vertx.ext.web.api.RequestParameters)11 HashMap (java.util.HashMap)11