SAP / cloud-sdk-js

Use the SAP Cloud SDK for JavaScript / TypeScript to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
165 stars 56 forks source link

OpenAPI generator - parameters in header are not added to the client #4484

Closed sven-petersen closed 2 months ago

sven-petersen commented 9 months ago

Describe the bug

Parameters in headers (in: header) cannot be passed to the generated OpenAPI client.

To Reproduce Steps to reproduce the behavior:

Generate an OpenAPI client for the following schema:

openapi: 3.0.3
info:
  title: Swagger Petstore - OpenAPI 3.0
  version: 1.0.11
paths:
  /pet:
    post:
      operationId: updatePet
      parameters:
        - $ref: "#/components/parameters/SomeParameterInHeader"
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Pet"
        required: true
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"
components:
  schemas:
    Pet:
      required:
        - name
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
  requestBodies:
    Pet:
      description: Pet object that needs to be added to the store
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Pet"
  parameters:
    SomeParameterInHeader:
      name: header-param
      in: header
      required: true
      schema:
        type: string
      examples:
        example1:
          value: 11111111-2222-3333-4444-555555555555

Check if the header parameter header-param can be set in the generated client.

Expected behavior

The parameter in the header ( header-param) can be passed as parameter to the generated client somewhere like so:

import * as myApi from "./gen/ckms-common-api/index.js";
myApi.DefaultApi.updatePet({
  name: "my dog",
  "header-param": "11111111-2222-3333-4444-555555555555"
});

Used Versions:

Impact / Priority

Affected development phase: Development

Additional context

Current workaround is to manually set the headers using

import * as myApi from "./gen/ckms-common-api/index.js";
myApi.DefaultApi.updatePet({
  name: "my dog",
})
  .addCustomHeaders({
    headerParam: "11111111-2222-3333-4444-555555555555",
  })
jjtang1985 commented 9 months ago

Hi @sven-petersen ,

Thanks for raising up. Using custom headers is the recommended way for passing header parameters for the time being.

I'll leave this ticket open and re-evaluate it later (e.g., the workaround does not work).

Best regards, Junjie

sven-petersen commented 2 months ago

This was implemented with https://sap.github.io/cloud-sdk/docs/js/release-notes#improvements-1 / aa0b849