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

[REQ] Generated client library should hardcode parameters that are required and can have Only Single valid value #16547

Open
prashant-pant opened this issue Sep 9, 2023 · 0 comments

Comments

@prashant-pant
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Consider below OpenAPI file

openapi: 3.0.3
info:
  title: Example Hello API
  description: ''
  version: v1
servers:
  - url: http://localhost
    description: Global Endpoint
paths:
  /v1/hello/{name}:
    get:
      tags:
        - hello_example
      operationId: Hello
      description: Say Hello
      parameters:
        - name: X-CUSTOM_CONSTANT_HEADER
          in: header
          required: true
          schema:
            type: string
            enum:
            - CONSTANT_VALUE
        - name: name
          in: path
          required: true
          schema:
            type: string
      responses:
        default:
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HelloResponse'
components:
  schemas:
    HelloResponse:
      type: object
      properties:
        message:
          type: string

The header X-CUSTOM_CONSTANT_HEADER is marked as required that means that clients must pass this header and the value of header can only be "CONSTANT_VALUE".
The code generated expects both CUSTOM_CONSTANT_HEADER and name as argument.

Describe the solution you'd like

The generated library code can hardcode the value of X-CUSTOM_CONSTANT_HEADER i.e. CONSTANT_VALUE in all requests and should be able to function with only name as argument.
The default behavior of library generator can remain unchanged for now and This feature can be enabled conditionally if we introduce a new flag/property for eg. autosetConstant and this is explicitly enabled via CLI/Config.

Describe alternatives you've considered

Below OpenAPI features are not useful in this case
Default : The OpenAPI Spec mentions that default value is the value which Server will use if client does not send any value. It does not describe default as the value which client will send if the value is not set by the caller.

Additional context

Stackoverflow Question asked

@prashant-pant prashant-pant changed the title [REQ] Generated client library should hardcode parameters that are required and can have single valid value [REQ] Generated client library should hardcode parameters that are required and can have Only Single valid value Sep 9, 2023
wing328 pushed a commit that referenced this issue Sep 15, 2023
…va (OkHttp) Implementation of #16547 (#16550)

* Autosets the parameters with the only value specified as enum if the parameter is also marked as required

* Autosets the parameters with the only value specified as enum if the parameter is also marked as required

* Autosets the parameters with the only value specified as enum if the parameter is also marked as required for Java default client.

* Autosets the parameters with the only value specified as enum if the parameter is also marked as required for Java default client.

* Autosets the parameters with the only value specified as enum if the parameter is also marked as required for Java default client.

* Autosets the parameters with the only value specified as enum if the parameter is also marked as required for Java default client.
prashant-pant added a commit to prashant-pant/openapi-generator that referenced this issue Oct 8, 2023
wing328 pushed a commit that referenced this issue Oct 16, 2023
…16761)

* Autoset constants (Required fields having single valid enum value) Python Implementation of #16547

* Fixing ``PythonClientCodegenTest.testHandleConstantParams`` for Windows platform.
AlanCitrix pushed a commit to AlanCitrix/openapi-generator that referenced this issue Oct 26, 2023
…penAPITools#16761)

* Autoset constants (Required fields having single valid enum value) Python Implementation of OpenAPITools#16547

* Fixing ``PythonClientCodegenTest.testHandleConstantParams`` for Windows platform.
wing328 pushed a commit that referenced this issue Mar 9, 2024
… Implementation of #16547 (#17954)

* Autoset constants (Required fields having single valid enum value) C# Implementation

* Update generichost/api.mustache & httpclient/api.mustache to autoset singleton enums values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant