use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.
the class BeanParamTest method shouldSerializeTypeParameter.
// tests issue #2466
@Test(description = "check array type of serialized BeanParam containing QueryParams")
public void shouldSerializeTypeParameter() {
OpenAPI openApi = new Reader(new OpenAPI()).read(MyBeanParamResource.class);
List<Parameter> getOperationParams = openApi.getPaths().get("/").getGet().getParameters();
Assert.assertEquals(getOperationParams.size(), 1);
Parameter param = getOperationParams.get(0);
Assert.assertEquals(param.getName(), "listOfStrings");
Schema<?> schema = param.getSchema();
// These are the important checks:
Assert.assertEquals(schema.getClass(), ArraySchema.class);
Assert.assertEquals(((ArraySchema) schema).getItems().getType(), "string");
}
use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.
the class ReaderTest method test2818.
@Test(description = "test ticket #2818 @Parameter annotation")
public void test2818() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(Ticket2818Resource.class);
Paths paths = openAPI.getPaths();
assertEquals(paths.size(), 1);
PathItem pathItem = paths.get("/bookstore/{id}");
assertNotNull(pathItem);
Operation operation = pathItem.getGet();
assertNotNull(operation);
assertEquals(operation.getParameters().get(0).getSchema().getType(), "integer");
assertEquals(operation.getParameters().get(0).getSchema().getFormat(), "int32");
}
use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.
the class ParameterDeserializer method deserialize.
@Override
public Parameter deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
Parameter result = null;
JsonNode node = jp.getCodec().readTree(jp);
JsonNode sub = node.get("$ref");
JsonNode inNode = node.get("in");
JsonNode desc = node.get("description");
if (sub != null) {
result = new Parameter().$ref(sub.asText());
if (desc != null && openapi31) {
result.description(desc.asText());
}
} else if (inNode != null) {
String in = inNode.asText();
ObjectReader reader = null;
ObjectMapper mapper = null;
if (openapi31) {
mapper = Json31.mapper();
} else {
mapper = Json.mapper();
}
if ("query".equals(in)) {
reader = mapper.readerFor(QueryParameter.class);
} else if ("header".equals(in)) {
reader = mapper.readerFor(HeaderParameter.class);
} else if ("path".equals(in)) {
reader = mapper.readerFor(PathParameter.class);
} else if ("cookie".equals(in)) {
reader = mapper.readerFor(CookieParameter.class);
}
if (reader != null) {
result = reader.with(DeserializationFeature.READ_ENUMS_USING_TO_STRING).readValue(node);
}
}
return result;
}
use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.
the class SpecFilter method filterOperation.
protected Operation filterOperation(OpenAPISpecFilter filter, Operation operation, String resourcePath, String key, Map<String, List<String>> params, Map<String, String> cookies, Map<String, List<String>> headers) {
if (operation != null) {
ApiDescription description = new ApiDescription(resourcePath, key);
Optional<Operation> filteredOperation = filter.filterOperation(operation, description, params, cookies, headers);
if (filteredOperation.isPresent()) {
List<Parameter> filteredParameters = new ArrayList<>();
Operation filteredOperationGet = filteredOperation.get();
Operation clone = new Operation();
clone.setCallbacks(filteredOperationGet.getCallbacks());
clone.setDeprecated(filteredOperationGet.getDeprecated());
clone.setDescription(filteredOperationGet.getDescription());
clone.setExtensions(filteredOperationGet.getExtensions());
clone.setExternalDocs(filteredOperationGet.getExternalDocs());
clone.setOperationId(filteredOperationGet.getOperationId());
clone.setSecurity(filteredOperationGet.getSecurity());
clone.setServers(filteredOperationGet.getServers());
clone.setSummary(filteredOperationGet.getSummary());
clone.setTags(filteredOperationGet.getTags());
List<Parameter> parameters = filteredOperationGet.getParameters();
if (parameters != null) {
for (Parameter parameter : parameters) {
Parameter filteredParameter = filterParameter(filter, operation, parameter, resourcePath, key, params, cookies, headers);
if (filteredParameter != null) {
filteredParameters.add(filteredParameter);
}
}
clone.setParameters(filteredParameters);
}
RequestBody requestBody = filteredOperation.get().getRequestBody();
if (requestBody != null) {
RequestBody filteredRequestBody = filterRequestBody(filter, operation, requestBody, resourcePath, key, params, cookies, headers);
clone.setRequestBody(filteredRequestBody);
}
ApiResponses responses = filteredOperation.get().getResponses();
ApiResponses clonedResponses = responses;
if (responses != null) {
responses.forEach((responseKey, response) -> {
ApiResponse filteredResponse = filterResponse(filter, operation, response, resourcePath, key, params, cookies, headers);
if (filteredResponse != null) {
clonedResponses.addApiResponse(responseKey, filteredResponse);
}
});
clone.setResponses(clonedResponses);
}
return clone;
}
}
return null;
}
use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.
the class SpecFilter method addPathItemSchemaRef.
private void addPathItemSchemaRef(PathItem pathItem, Set<String> referencedDefinitions) {
if (pathItem.getParameters() != null) {
for (Parameter parameter : pathItem.getParameters()) {
addSchemaRef(parameter.getSchema(), referencedDefinitions);
addContentSchemaRef(parameter.getContent(), referencedDefinitions);
}
}
Map<PathItem.HttpMethod, Operation> ops = pathItem.readOperationsMap();
for (Operation op : ops.values()) {
if (op.getRequestBody() != null) {
addContentSchemaRef(op.getRequestBody().getContent(), referencedDefinitions);
}
if (op.getResponses() != null) {
for (String keyResponses : op.getResponses().keySet()) {
ApiResponse response = op.getResponses().get(keyResponses);
if (response.getHeaders() != null) {
for (String keyHeaders : response.getHeaders().keySet()) {
Header header = response.getHeaders().get(keyHeaders);
addSchemaRef(header.getSchema(), referencedDefinitions);
addContentSchemaRef(header.getContent(), referencedDefinitions);
}
}
addContentSchemaRef(response.getContent(), referencedDefinitions);
}
}
if (op.getParameters() != null) {
for (Parameter parameter : op.getParameters()) {
addSchemaRef(parameter.getSchema(), referencedDefinitions);
addContentSchemaRef(parameter.getContent(), referencedDefinitions);
}
}
if (op.getCallbacks() != null) {
for (String keyCallback : op.getCallbacks().keySet()) {
Callback callback = op.getCallbacks().get(keyCallback);
for (PathItem callbackPathItem : callback.values()) {
addPathItemSchemaRef(callbackPathItem, referencedDefinitions);
}
}
}
}
}
Aggregations