OpenAPITools / OpenAPITools/openapi-generator
[BUG] [scala-sttp] [scala-akka] OpenAPI generator does not generate additional properties of type Object
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
When I use the scala-sttp / scala-akka generators, the case classes generated for JSON models in OpenAPI spec do not include the additional properties of type Object. Details follow.
Here is the OpenAPI snippet showing the Element JSON model. Note the additionalProperties at the end of type Object.
Element:
type: object
properties:
'@type':
type: string
'@id':
type: string
format: uuid
identifier:
type: string
format: uuid
additionalProperties:
type: object
Here is the case class for Element generated when using scala-sttp and scala-akka generators. As you can see, there is no generic property in the case class that is of type Map to hold the additional properties in Element.
import java.util.UUID
import org.openapitools.client.core.ApiModel
case class Element (
`type`: Option[String] = None,
id: Option[UUID] = None,
identifier: Option[UUID] = None
) extends ApiModel
On the contrary, the Java generator handles this correctly. Element class inherits HashMap.
public class Element extends HashMap<String, Object> {
public static final String SERIALIZED_NAME_AT_TYPE = "@type";
@SerializedName(SERIALIZED_NAME_AT_TYPE)
private String atType;
public static final String SERIALIZED_NAME_AT_ID = "@id";
@SerializedName(SERIALIZED_NAME_AT_ID)
private UUID atId;
public static final String SERIALIZED_NAME_IDENTIFIER = "identifier";
@SerializedName(SERIALIZED_NAME_IDENTIFIER)
private UUID identifier;
}
openapi-generator version
OpenAPI 4.3.1. It is not a regression. This has never worked for us.
OpenAPI declaration file content or url
See above in the Description.
Generation Details
scala-sttp command used
java -jar openapi-generator-cli-4.3.1.jar generate --api-package com.org.api --model-package com.org.model -i my_openapi.yaml -g scala-akka -o ./output/scala-sttp
scala-akka command used
java -jar openapi-generator-cli-4.3.1.jar generate --api-package com.org.api --model-package com.org.model -i my_openapi.yaml -g scala-akka -o ./output/scala-akka
java command used
java -jar openapi-generator-cli-4.3.1.jar generate --api-package com.org.api --model-package com.org.model -i my_openapi.yaml -g scala-akka -o ./output/scala-java
Steps to reproduce
Provided in the Description above.
Related issues/PRs
None that I have seen.
Suggest a fix
No suggestions.
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 reproducing the issue with the provided OpenAPI Element schema and the scala-sttp and scala-akka generator commands. Inspect those generator entry points and compare their model output with the Java generator's handling of additionalProperties. Done means the generated Scala case classes preserve arbitrary Object-valued additional properties and the behavior is covered by the relevant generator tests.
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
- Mostly clear
- Newbie friendliness
- 38/100