OpenAPITools / OpenAPITools/openapi-generator
[BUG][scala-sttp] The scala-sttp generator applies security schemes incorrectly.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The scala-sttp generator does not apply security correctly when there are multiple schemes available. For example, if I define a bearer token, API key and basic username and password authentication, the generated code expects all three to be provided with each call:
def hello(username: String, password: String, apiKey: String, bearerToken: String)(name: String): Request[Either[Either[String, String], Unit], Any]
The API should only expect one of the following:
- username and password
- apiKey
- bearerToken
openapi-generator version
Found on version 7.2.0 and confirmed the same behaviour on the master branch.
OpenAPI declaration file content or url
openapi: 3.0.3
info:
version: 2.7.0
title: Hello API
tags:
- name: Hello
description: Part of the example hello API.
paths:
/hello:
get:
tags:
- Hello
summary: Example endpoint says hello
operationId: sayHello
responses:
'200':
description: Some hello response.
content:
application/json:
schema:
$ref: '#/components/schemas/HelloResponse'
components:
schemas:
HelloResponse:
type: object
properties:
message:
type: string
securitySchemes:
BasicAuth:
type: http
scheme: basic
BearerAuth:
type: http
scheme: bearer
ApiKeyAuth:
type: apiKey
in: header
name: X-API-Key
security:
- BasicAuth: []
- BearerAuth: []
- ApiKeyAuth: []
Generation Details
No special steps. I'm using the gradle plugin and setting generatorName.set("scala-sttp")
Steps to reproduce
Generate a scala-sttp client from the spec above.
Related issues/PRs
Suggest a fix
Other clients, such as the Java and Python ones do not require all security schemes with every call. For example, the Java client only applies basic auth if both the user and password are defined. It only sets the api key header if the api key has been set to something. Otherwise, it skips the step and does not set the header. The Scala client should do the same.
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 by generating the provided OpenAPI YAML with the scala-sttp generator through the Gradle plugin and inspect the generated hello method signature. Trace how the three security schemes are applied, then verify that generated calls can use BasicAuth, BearerAuth, or ApiKeyAuth independently rather than requiring all credentials.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, scala
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100