swagger-api / swagger-api/swagger-codegen

Typescript-angular api generated without extraHttpRequestParams

Open
#10,840 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

This is a problem because one endpoint returns image/jpeg and we need to override angular HTTP request options to accept blob not json, but can't override this without extraHttpRequestParams in the method.

Method signature:

  public apiGetLastCameraShot(
    id: string,
    camera_id: string,
    body?: CameraShotBody,
    observe?: 'body',
    reportProgress?: boolean
  ): Observable<any> {
Swagger-codegen version

3.0.22

Swagger declaration file content or url
swagger: '2.0'
info:
  description: This is a swagger UI interface
  version: '1.0.0'
  title: OpenAPI BackEnd direct interfacing via SwaggerUI
consumes:
  - application/json
produces:
  - application/json

basePath: /api
/photos/{id}/camera/{camera_id}/lastshot:
    post:
      operationId: api.get_last_camera_shot
      summary: Returns last shot of camera
      description: Returns last shot of camera
      consumes:
        - application/json
      produces:
        - image/jpeg
      parameters:
        - name: id
          in: path
          description: Id of the camera machine
          type: string
          required: true
        - name: camera_id
          in: path
          description: Id of the camera to get the last shot from
          type: string
          required: true
        - name: shot_settings
          in: body
          description: Settings to generate the camera shot
          required: false
          schema:
            type: object
            title: CameraShotBody
            properties:
              width:
                type: integer
              height:
                type: integer
      responses:
        200:
          description: Successfully returned camera shot
Command line used for generation

swagger-codegen generate -i http://localhost:8800/api/swagger.json -l typescript-angular -o src/app/swagger -c swagger-config.json"

swagger-config file:

{
  "modelPropertyNaming": "original"
}
Steps to reproduce

Mac OSX 14
brew install swagger-codegen // 3.022
swagger-codegen generate -i http://localhost:8800/api/swagger.json -l typescript-angular -o src/app/swagger -c swagger-config.json" // the swagger.yml file I posted above is served as JSON locally

Related issues/PRs

Searched and found https://github.com/swagger-api/swagger-codegen/issues/4037 which is similar goal but in their case it seemed like the extraHttpRequestParams param was being generated, but not used.

Suggest a fix/enhancement

I'm pretty confused why - every code sample I've found online seems to have extraHttpRequestParams generated in the method signature.
Also this line containing it, doesn't seem to be behind any conditional in mustache: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angularjs/api.mustache#L36

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 with modules/swagger-codegen/src/main/resources/typescript-angularjs/api.mustache and compare its generated output with the typescript-angular method signature shown in the issue. Reproduce with the supplied Swagger definition, swagger-config.json, and generation command; done means the generated API method exposes extraHttpRequestParams so Angular HTTP request options can be overridden for the image/jpeg response.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.