Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow programmatic model name customization #4790

Open
T3rm1 opened this issue Nov 19, 2024 · 0 comments
Open

Allow programmatic model name customization #4790

T3rm1 opened this issue Nov 19, 2024 · 0 comments

Comments

@T3rm1
Copy link

T3rm1 commented Nov 19, 2024

Introduce a method that can be overriden, or another mechanism, to allow for model name customization. An example would be to have a suffix "Enum" for all enum models resolved as ref.

Doing this with a custom model resolver doesn't work.

public class EnumModelConverter implements ModelConverter {

	@Override
	public Schema<?> resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
		if (chain.hasNext()) {
			if (type.getType() instanceof JavaType javaType) {
				if (javaType.isEnumType()) {
					if (!javaType.getRawClass().getSimpleName().endsWith("Enum")) {
						type.setName(javaType.getRawClass().getSimpleName() + "Enum");
					}
				}
			} else if (type.getType() instanceof Class<?> clazz) {
				if (clazz.isEnum()) {
					if (!clazz.getSimpleName().endsWith("Enum")) {
						type.setName(clazz.getSimpleName() + "Enum");
					}
				}
			}
			return chain.next().resolve(type, context, chain);
		}
		return null;
	}
}

While this seems to work, it fails as soon as you have an enum with a custom name in its Schema annotation.

@Schema(name = "SomeClassStatus")
public enum Status {
    ONE, TWO
}

Proposal:
Add a protected method after

that allows to customize the name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant