use of com.github.victools.jsonschema.generator.MethodScope in project jsonschema-generator by victools.
the class SchemaGenerationContextImpl method collectMethod.
/**
* Preparation Step: add the given method to the specified {@link Map}.
*
* @param method declared method that should be added to the specified node
* @param collectedProperties collection of fields/methods to be added as properties
* @param requiredProperties set of properties value required
*/
private void collectMethod(MethodScope method, Map<String, MemberScope<?, ?>> collectedProperties, Set<String> requiredProperties) {
final MethodScope methodWithNameOverride;
final String propertyName;
if (method.isFakeContainerItemScope()) {
methodWithNameOverride = method;
propertyName = method.getSchemaPropertyName();
} else {
String propertyNameOverride = this.generatorConfig.resolvePropertyNameOverride(method);
methodWithNameOverride = propertyNameOverride == null ? method : method.withOverriddenName(propertyNameOverride);
propertyName = methodWithNameOverride.getSchemaPropertyName();
if (this.generatorConfig.isRequired(method)) {
requiredProperties.add(propertyName);
}
if (collectedProperties.containsKey(propertyName)) {
logger.debug("ignoring overridden {}.{}", methodWithNameOverride.getDeclaringType(), methodWithNameOverride.getDeclaredName());
return;
}
}
collectedProperties.put(propertyName, methodWithNameOverride);
}
use of com.github.victools.jsonschema.generator.MethodScope in project jsonschema-generator by victools.
the class SchemaGenerationContextImpl method generateArrayDefinition.
/**
* Preparation Step: add the given targetType (which was previously determined to be an array type).
*
* @param targetScope (possibly generic) array type to add
* @param definition node in the JSON schema to which all collected attributes should be added
* @param isNullable whether the field/method's return value the targetType refers to is allowed to be null in the declaring type
*/
private void generateArrayDefinition(TypeScope targetScope, ObjectNode definition, boolean isNullable) {
if (isNullable) {
ArrayNode typeArray = this.generatorConfig.createArrayNode().add(this.getKeyword(SchemaKeyword.TAG_TYPE_ARRAY)).add(this.getKeyword(SchemaKeyword.TAG_TYPE_NULL));
definition.set(this.getKeyword(SchemaKeyword.TAG_TYPE), typeArray);
} else {
definition.put(this.getKeyword(SchemaKeyword.TAG_TYPE), this.getKeyword(SchemaKeyword.TAG_TYPE_ARRAY));
}
if (targetScope instanceof MemberScope<?, ?> && !((MemberScope<?, ?>) targetScope).isFakeContainerItemScope()) {
MemberScope<?, ?> fakeArrayItemMember = ((MemberScope<?, ?>) targetScope).asFakeContainerItemScope();
JsonNode fakeItemDefinition;
if (targetScope instanceof FieldScope) {
fakeItemDefinition = this.populateFieldSchema((FieldScope) fakeArrayItemMember);
} else if (targetScope instanceof MethodScope) {
fakeItemDefinition = this.populateMethodSchema((MethodScope) fakeArrayItemMember);
} else {
throw new IllegalStateException("Unsupported member type: " + targetScope.getClass().getName());
}
definition.set(this.getKeyword(SchemaKeyword.TAG_ITEMS), fakeItemDefinition);
} else {
ObjectNode arrayItemTypeRef = this.generatorConfig.createObjectNode();
definition.set(this.getKeyword(SchemaKeyword.TAG_ITEMS), arrayItemTypeRef);
this.traverseGenericType(targetScope.getContainerItemType(), arrayItemTypeRef, false);
}
}
use of com.github.victools.jsonschema.generator.MethodScope in project jsonschema-generator by victools.
the class SchemaGenerationContextImplTest method testCreateStandardDefinitionReferenceForMethod_noCustomDefinition.
@Test
public void testCreateStandardDefinitionReferenceForMethod_noCustomDefinition() {
MethodScope targetMethod = this.getTestClassMethod("isBooleanField");
JsonNode result = this.contextImpl.createStandardDefinitionReference(targetMethod, null);
Assert.assertEquals("{\"allOf\":[{},{\"title\":\"Method Title\"}]}", result.toString());
}
use of com.github.victools.jsonschema.generator.MethodScope in project jsonschema-generator by victools.
the class SchemaGenerationContextImplTest method testCreateStandardDefinitionReferenceForMethod_withCustomTypeDefinition.
@Test
public void testCreateStandardDefinitionReferenceForMethod_withCustomTypeDefinition() {
Mockito.doReturn(new CustomDefinition(this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom type"), true)).when(this.contextImpl.getGeneratorConfig()).getCustomDefinition(Mockito.any(ResolvedType.class), Mockito.any(), Mockito.any());
MethodScope targetMethod = this.getTestClassMethod("isBooleanField");
JsonNode result = this.contextImpl.createStandardDefinitionReference(targetMethod, null);
Assert.assertEquals("{\"allOf\":[{\"$comment\":\"custom type\",\"description\":\"Type Description\"},{\"title\":\"Method Title\"}]}", result.toString());
}
use of com.github.victools.jsonschema.generator.MethodScope in project jsonschema-generator by victools.
the class MethodExclusionModuleTest method testIgnoreCheck.
@Test
@Parameters
@TestCaseName("{method}({1}: {0} => {2}) [{index}]")
public void testIgnoreCheck(String testMethodName, String supplierMethodName, boolean ignored) throws Exception {
MethodExclusionModule moduleInstance = (MethodExclusionModule) MethodExclusionModule.class.getMethod(supplierMethodName).invoke(null);
moduleInstance.applyToConfigBuilder(this.builder);
MethodScope method = this.getTestClassMethod(testMethodName);
Assert.assertEquals(ignored, this.methodConfigPart.shouldIgnore(method));
}
Aggregations