OpenAPITools / OpenAPITools/openapi-generator
[REQ] Generated client library should hardcode parameters that are required and can have Only Single valid value
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with OpenAPI parameter handling and the generator's CLI/configuration options; the issue provides an OpenAPI example but names no implementation files or tests. Determine how an opt-in setting could recognize required parameters with a single enum value and make generated clients supply that value, then verify the generated call requires only the remaining parameter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100