OpenAPITools / OpenAPITools/openapi-generator

[INFO][TYPESCRIPT] Java to typescript code generation

Open
#18,717 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the typescript-angular output from openapi-generator v7.5.0 and the client-config.yaml settings, then compare it with the dist output produced by ng-packagr. Check whether the three observe overloads are expected for the generated getMETHODTHING method and document whether the generator configuration or packaging step accounts for the difference.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, java, openapi, typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.