Skip to content

Conversation

@Mattias-Sehlstedt
Copy link
Contributor

Uses the functionality introduced with #21950 to support interface-inheritance definitions with vendor extensions for client generation as well. This is for example useful when the schemas in a oneOf does not refer to some shared schema that carries the discriminator.

Specification example:

openapi: 3.0.1
info:
  title: some
  version: 1.0.0
servers:
  - url: http://localhost:8080
    description: Local server
paths:
  "/one-of-with-without-all-of-inheritance":
    get:
      operationId: WithoutAllOfEndpoint
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                oneOf:
                  - "$ref": "#/components/schemas/Child1"
                  - "$ref": "#/components/schemas/Child2"
                discriminator:
                  propertyName: jobType
                  mapping:
                    Child1: "#/components/schemas/Child1"
                    Child2: "#/components/schemas/Child2"
components:
  schemas:
    Child1:
      type: object
      properties:
        jobType:
          type: string
        property1:
          type: string
    Child2:
      type: object
      properties:
        jobType:
          type: string
        property2:
          type: string

Note that this does not solve the issue by itself, since the generated interface will look like

@JsonIgnoreProperties(
  value = ["jobType"], // ignore manually set jobType, it will be automatically generated by Jackson during serialization
  allowSetters = true // allows the jobType to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "jobType", visible = true)
@JsonSubTypes(
    JsonSubTypes.Type(value = AllOfChild1::class, name = "AllOfChild1"),
    JsonSubTypes.Type(value = AllOfChild2::class, name = "AllOfChild2")
)

interface WithAllOfEndpoint200Response {

    @get:JsonProperty("jobType")
    val jobType: kotlin.String?
    @get:JsonProperty("property1")
    val property1: kotlin.String?
    @get:JsonProperty("property2")
    val property2: kotlin.String?

}

rather than the more correct

@JsonIgnoreProperties(
  value = ["jobType"], // ignore manually set jobType, it will be automatically generated by Jackson during serialization
  allowSetters = true // allows the jobType to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "jobType", visible = true)
@JsonSubTypes(
    JsonSubTypes.Type(value = AllOfChild1::class, name = "AllOfChild1"),
    JsonSubTypes.Type(value = AllOfChild2::class, name = "AllOfChild2")
)

interface WithAllOfEndpoint200Response {

    @get:JsonProperty("jobType")
    val jobType: kotlin.String?

}

(what has been corrected is that fields that are not the discriminator has been removed).

This is tied to a separate issue that I plan to adjust for in a separate PR. It has to do with how a discriminator is interpreted and generated in the data_class.mustache and the

{{#discriminator}}{{#vars}}{{#required}}
{{>interface_req_var}}{{/required}}{{^required}}
{{>interface_opt_var}}{{/required}}{{/vars}}{{/discriminator}}

definition.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

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 this pull request may close these issues.

1 participant