use of com.google.api.server.spi.config.model.ApiParameterConfig in project endpoints-java by cloudendpoints.
the class DiscoveryGenerator method convertMethodParameters.
private Map<String, JsonSchema> convertMethodParameters(ApiMethodConfig methodConfig) {
Map<String, JsonSchema> parameters = Maps.newLinkedHashMap();
Collection<String> pathParameters = methodConfig.getPathParameters();
for (ApiParameterConfig parameterConfig : methodConfig.getParameterConfigs()) {
if (parameterConfig.getClassification() == Classification.API_PARAMETER) {
parameters.put(parameterConfig.getName(), convertMethodParameter(parameterConfig, pathParameters.contains(parameterConfig.getName())));
}
}
return parameters;
}
use of com.google.api.server.spi.config.model.ApiParameterConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReader method readMethodRequestParameter.
private void readMethodRequestParameter(ApiMethodConfig methodConfig, Annotation parameterName, Annotation description, Annotation nullable, Annotation defaultValue, TypeToken<?> type) throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
String parameterNameString = null;
if (parameterName != null) {
parameterNameString = getAnnotationProperty(parameterName, "value");
}
String descriptionString = null;
if (description != null) {
descriptionString = getAnnotationProperty(description, "value");
}
String defaultValueString = null;
if (defaultValue != null) {
defaultValueString = getAnnotationProperty(defaultValue, "value");
}
ApiParameterConfig parameterConfig = methodConfig.addParameter(parameterNameString, descriptionString, nullable != null, defaultValueString, type);
Annotation apiSerializer = type.getRawType().getAnnotation(annotationTypes.get("ApiTransformer"));
if (apiSerializer != null) {
Class<? extends Transformer<?, ?>> serializer = getAnnotationProperty(apiSerializer, "value");
parameterConfig.setSerializer(serializer);
}
if (parameterConfig.isRepeated()) {
TypeToken<?> repeatedItemType = parameterConfig.getRepeatedItemType();
apiSerializer = repeatedItemType.getRawType().getAnnotation(annotationTypes.get("ApiTransformer"));
if (apiSerializer != null) {
Class<? extends Transformer<?, ?>> repeatedItemSerializer = getAnnotationProperty(apiSerializer, "value");
parameterConfig.setRepeatedItemSerializer(repeatedItemSerializer);
}
}
}
use of com.google.api.server.spi.config.model.ApiParameterConfig in project endpoints-java by cloudendpoints.
the class ApiConfigValidator method validateResourceAndFieldNames.
private void validateResourceAndFieldNames(ApiMethodConfig methodConfig) throws PropertyParameterNameConflictException {
for (ApiParameterConfig parameterConfig : methodConfig.getParameterConfigs()) {
if (parameterConfig.getClassification() == Classification.RESOURCE) {
Schema schema = schemaRepository.getOrAdd(parameterConfig.getSchemaBaseType(), methodConfig.getApiConfig());
Set<String> fieldNames = schema.fields().keySet();
for (ApiParameterConfig parameter : methodConfig.getParameterConfigs()) {
if (parameter.getClassification() == Classification.API_PARAMETER && !"id".equals(parameter.getName()) && fieldNames.contains(parameter.getName())) {
log.atWarning().log("Parameter %s conflicts with a resource field name. This may " + "result in unexpected values in the request.", parameter.getName());
}
}
}
}
}
use of com.google.api.server.spi.config.model.ApiParameterConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testKnownParameterizedType.
@Test
public void testKnownParameterizedType() throws Exception {
@Api
class Bar<T1> {
@SuppressWarnings("unused")
public void bar(T1 t1) {
}
}
class Foo extends Bar<Integer> {
}
ApiConfig config = createConfig(Foo.class);
annotationReader.loadEndpointMethods(serviceContext, Foo.class, config.getApiClassConfig().getMethods());
ApiParameterConfig parameter = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Foo.class.getSuperclass().getDeclaredMethod("bar", Object.class))).getParameterConfigs().get(0);
assertEquals(ApiParameterConfig.Classification.API_PARAMETER, parameter.getClassification());
}
use of com.google.api.server.spi.config.model.ApiParameterConfig in project endpoints-java by cloudendpoints.
the class ApiConfigAnnotationReaderTest method testParameterAnnotations.
@Test
public void testParameterAnnotations() throws Exception {
@Api
class Endpoint {
@SuppressWarnings("unused")
public void method(@Named("foo") @Nullable @DefaultValue("4") int foo) {
}
}
ApiConfig config = createConfig(Endpoint.class);
annotationReader.loadEndpointClass(serviceContext, Endpoint.class, config);
annotationReader.loadEndpointMethods(serviceContext, Endpoint.class, config.getApiClassConfig().getMethods());
ApiMethodConfig methodConfig = Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values());
ApiParameterConfig parameterConfig = Iterables.getOnlyElement(methodConfig.getParameterConfigs());
validateParameter(parameterConfig, "foo", true, "4", int.class, null, int.class);
}
Aggregations