openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[INFO][TYPESCRIPT] Java to typescript code generation

Open mje0002 opened this issue 1 year ago • 0 comments

Description

Recently, we upgraded our Java projects from version 11 to 21 and transitioned to using the openapi-generator-cli to support OpenAPI 3, moving away from Swagger 2.0. After completing these main upgrades, we generated the client (Typescript-Angular) using this new tool. We observed that the new tool generates methods per Observe type, and the ng-packagr seems to indicate there are three distinct method implementations, even though there is only one. Could you please clarify if this behavior is expected, or if we might have set something up incorrectly?

openapi-generator version

v7.5.0

Java Controller - with Endpoint

@RestController
@Tag(name = "TAG NAME")
@RequestMapping("/AN_ENDPOINT")
public class TheController {

...

	@GetMapping
	public Map<String, FormField> getMETHODTHING() {
		return SOMESERVICE.getSERVICEMETHOD();
	}

...

END

What the openapi-generator-cli spits out before ng-packagr is run

    /**
     * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
     * @param reportProgress flag to report request and response progress.
     */
    public getMETHODTHING(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/hal+json', context?: HttpContext}): Observable<{ [key: string]: FormField; }>;
    public getMETHODTHING(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/hal+json', context?: HttpContext}): Observable<HttpResponse<{ [key: string]: FormField; }>>;
    public getMETHODTHING(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/hal+json', context?: HttpContext}): Observable<HttpEvent<{ [key: string]: FormField; }>>;
    public getMETHODTHING(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/hal+json', context?: HttpContext}): Observable<any> {
               ...
               Meat and Potatoes happens here
               ...
    }

What is generated to dist folder after ng-packagr runs

    /**
     * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
     * @param reportProgress flag to report request and response progress.
     */
    getMETHODTHING(observe?: 'body', reportProgress?: boolean, options?: {
        httpHeaderAccept?: 'application/hal+json';
        context?: HttpContext;
    }): Observable<{
        [key: string]: FormField;
    }>;
    getMETHODTHING(observe?: 'response', reportProgress?: boolean, options?: {
        httpHeaderAccept?: 'application/hal+json';
        context?: HttpContext;
    }): Observable<HttpResponse<{
        [key: string]: FormField;
    }>>;
    getMETHODTHING(observe?: 'events', reportProgress?: boolean, options?: {
        httpHeaderAccept?: 'application/hal+json';
        context?: HttpContext;
    }): Observable<HttpEvent<{
        [key: string]: FormField;
    }>>;
Command line used for generation

docker run --rm --user 1000 -v "${PWD}/service/target:/local"
openapitools/openapi-generator-cli:v7.5.0 generate
--global-property apiTests=false,apiDocs=false,modelTests=false,modelDocs=false
-i /local/generated-docs/swagger/swagger.json
-g typescript-angular
-o /local/angular-client -c /local/angular-client-config.yaml

client-config.yaml

fileNaming: camelCase
npmName: "NAME"
npmVersion: '0.0.0-0-placeholder'
npmRepository: 'REPO'
useSingleRequestParameter: true
ngVersion: '16.2.12'
disallowAdditionalPropertiesIfNotPresent: false
withInterfaces: true

mje0002 avatar May 20 '24 19:05 mje0002