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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations