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

Spring contoller method arguments are not processed with custom TypeProcessor #746

Open
porunov opened this issue Nov 10, 2021 · 1 comment

Comments

@porunov
Copy link

porunov commented Nov 10, 2021

I have a controller method like:

@RequestMapping(value = "/hello/{id}/world", method = RequestMethod.GET)
public ResponseEntity<GetResponse> getMethod(@PathVariable String id, @RequestParam(required = false) Set<String> queryParameter) {
    return null;
}

I also have a custom type resolver:

public class CustomTypeProcessor implements TypeProcessor {
    @Override
    public Result processType(Type javaType, Context context) {
        if(context.getTypeContext() != null){
            if(javaType.getTypeName().startsWith("java.util.Set")){
                System.out.println("Hello World");
            }
        }
        return null;
    }
}

I'm using Gradle build which looks like:

apply plugin: 'cz.habarta.typescript-generator'
apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    compile "cz.habarta.typescript-generator:typescript-generator-core:2.33.956"
    compile "cz.habarta.typescript-generator:typescript-generator-spring:2.33.956"
}

buildscript {

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath ("cz.habarta.typescript-generator:typescript-generator-gradle-plugin:2.33.956")
        classpath ("cz.habarta.typescript-generator:typescript-generator-spring:2.33.956")
    }

}

generateTypeScript {
    jsonLibrary = 'jackson2'
    classPatterns = [
            'path.to.dto.**DTO',
            'path.to.controllers.**'
    ]
    outputFile = 'build/output.ts'
    outputKind = 'global'
    outputFileType = 'implementationFile'
    mapClasses = 'asClasses'
    mapEnum = 'asEnum'
    nonConstEnums = true
    optionalProperties = 'useLibraryDefinition'
    scanSpringApplication = true
    generateSpringApplicationClient = true
    generateSpringApplicationInterface = true
    customTypeProcessor = 'path.to.CustomTypeProcessor'
}

I noticed that CustomTypeProcessor is triggered for all DTO fields but it's not triggered for any method arguments.
It would be really great if we could use custom processors to process method arguments as well.

@porunov
Copy link
Author

porunov commented Feb 5, 2022

With #788 it's possible to add logic which replaces / changes argument types of necessary arguments before typescript code is generated. So, it could be used as a workaround for this issue.

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