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

Resolve schema modules in discriminator mapping #511

Merged
merged 1 commit into from Nov 14, 2022

Conversation

mbuhot
Copy link
Collaborator

@mbuhot mbuhot commented Nov 14, 2022

fixes #387

Given a schemas such as PetAppointmentRequest from the test suite:

defmodule PetAppointmentRequest do
    OpenApiSpex.schema(%{
      title: "PetAppointmentRequest",
      description: "POST body for making a pet appointment",
      type: :object,
      oneOf: [
        TrainingAppointment,
        GroomingAppointment
      ],
      discriminator: %OpenApiSpex.Discriminator{
        propertyName: "appointment_type",
        mapping: %{
          "training" => TrainingAppointment,
          "grooming" => GroomingAppointment
        }
      }
    })
  end

The resolve_schema_modules function will now replace modules appearing in the discriminator.property.mapping map, with the appropriate path to the schema, eg "#/components/schemas/TrainingAppointment".

Rendered to JSON gives:

      "PetAppointmentRequest": {
        "description": "POST body for making a pet appointment",
        "discriminator": {
          "mapping": {
            "grooming": "#/components/schemas/GroomingAppointment",
            "training": "#/components/schemas/TrainingAppointment"
          },
          "propertyName": "appointment_type"
        },
        "oneOf": [
          {
            "$ref": "#/components/schemas/TrainingAppointment"
          },
          {
            "$ref": "#/components/schemas/GroomingAppointment"
          }
        ],
        "title": "PetAppointmentRequest",
        "type": "object"
      },

@mbuhot mbuhot merged commit f54a044 into master Nov 14, 2022
@mbuhot mbuhot deleted the fix-schemas-in-discriminator-mapping branch November 14, 2022 01:52
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.

Discriminator mapping is rendered wrong in json
1 participant