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

oneOf is translated to Object when one of the options is a simple type. #444

Closed
Tracked by #1247
fjtirado opened this issue Oct 28, 2024 · 0 comments · Fixed by #448
Closed
Tracked by #1247

oneOf is translated to Object when one of the options is a simple type. #444

fjtirado opened this issue Oct 28, 2024 · 0 comments · Fixed by #448
Assignees

Comments

@fjtirado
Copy link
Collaborator

Lets take an example to illustrate the issue

This portion of the schema

  with:
            type: object
            title: HTTPArguments
            description: The HTTP call arguments.
            properties:
              method:
                type: string
                title: WithHTTPMethod
                description: The HTTP method of the HTTP request to perform.
              endpoint:
                title: WithHTTPEndpoint
                description: The HTTP endpoint to send the request to.
                oneOf:
                  - $ref: '#/$defs/endpoint'
                  - $ref: '#/$defs/runtimeExpression'
                  - title: LiteralEndpoint
                    type: string
                    format: uri-template

is translated to

public class HTTPArguments implements Serializable
{
    @JsonProperty("endpoint")
    @JsonPropertyDescription("The HTTP endpoint to send the request to.")
    @NotNull
    private Object endpoint;
}

Alhought an Endpoint class is generated, when using this definition

do:
  - getPet:
      call: http
      with:
        method: get
        endpoint:
          uri: https://petstore.swagger.io/v2/pet/{petId}
        output: response

A LinkedHasHMap rather than an Endpoint (a class that is generated, but never used) instance is assigned to endpooint filed, which forces the user of the SDK to write (even incorreclty assuming the uri field is used, which is not necessarily true) this ugly code
String uri = ((Map) httpArgs.getEndpoint()).get("uri").toString();

A custom deserializer wont be enough, because although it will allow to use this somehow "better" form
((Endpoint) httpArgs.getEndpoint()).getUri()
still have obvious problems: Besides being prompt to ClassCastExcpetion, it forces the user to somehow know that endpoint field might hold an Endpoint object
Therefore, we need to make a breaking backward compatibility change (which is one of the advantages of being in alpha state ;), and rather than an Object field for endpoint, generate a new Union class with getters for all possible value types, as current happen when all possible types are generated classes, for example Call

@fjtirado fjtirado self-assigned this Oct 28, 2024
fjtirado added a commit to fjtirado/sdk-java that referenced this issue Oct 28, 2024
fjtirado added a commit to fjtirado/sdk-java that referenced this issue Oct 28, 2024
fjtirado pushed a commit to fjtirado/sdk-java that referenced this issue Oct 28, 2024
Bumps [ch.qos.logback:logback-classic](https://github.com/qos-ch/logback)
from 1.5.10 to 1.5.11.
- [Commits](qos-ch/logback@v_1.5.10...v_1.5.11)

---
updated-dependencies:
- dependency-name: ch.qos.logback:logback-classic
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
[Fix serverlessworkflow#444] Handling multiple strings
fjtirado pushed a commit to fjtirado/sdk-java that referenced this issue Oct 28, 2024
Signed-off-by: Francisco Javier Tirado Sarti <[email protected]>
fjtirado pushed a commit to fjtirado/sdk-java that referenced this issue Oct 28, 2024
Signed-off-by: Francisco Javier Tirado Sarti <[email protected]>
fjtirado pushed a commit to fjtirado/sdk-java that referenced this issue Oct 28, 2024
fjtirado added a commit that referenced this issue Oct 28, 2024
[Fix #444] Wrapper class for anyOf containing strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant