Hello guys! I'm implementing BDCT using an OAS fi...
# pact-broker
c
Hello guys! I'm implementing BDCT using an OAS file provided by a banking platform. The file is in JSON file and it's working fine in Swagger editor. Based on the documentation I've been reading, it's recommended to dereference the nodes of the file, and that's what I've done. However, I noticed I get errors like this when comparing pacts in Pactflow (see screenshot too):
Copy code
Unable to parse "oas": Swagger schema validation failed. Data does not match any schemas from 'oneOf' at #/paths//v1/plan-migrations:batchGet/get/responses/200 Data does not match any schemas from 'oneOf' at #/paths//v1/plan-migrations:batchGet/get/responses/200/content/application/json/schema Data does not match any schemas from 'oneOf' at #/content/application/json/schema/properties/plan_migrations Data does not match any schemas from 'oneOf' at #/properties/plan_migrations/additionalProperties Data does not match any schemas from 'oneOf' at #/additionalProperties/properties/supervisor_contract_version_migration Expected type array but found type boolean at #/properties/supervisor_contract_version_migration/required Missing required property: $ref at #/properties/supervisor_contract_version_migration Missing required property: $ref at #/additionalProperties Expected type boolean but found type object at #/additionalProperties Missing required property: $ref at #/properties/plan_migrations Missing required property: $ref at #/content/application/json/schema Missing required property: $ref at #/paths//v1/plan-migrations:batchGet/get/responses/200 JSON_OBJECT_VALIDATION_FAILED
In particular, the original format of the node producing the error is as follows:
Copy code
"supervisor_contract_version_migration": {
  "$ref": "#/components/schemas/plansSupervisorContractVersionMigration",
  "required": true
}
After dereference it, I get the following:
Copy code
"supervisor_contract_version_migration": {
  "required": true,
  "type": "object",
  "properties": {
      "from_supervisor_contract_version_ids": {
          "type": "array",
          "items": {
              "type": "string"
          },
          "description": "The Supervisor Contract version IDs to migrate plans from.\n\nRequired.\nMin count: 1."
      },
      "to_supervisor_contract_version_id": {
          "type": "string",
          "description": "The Supervisor Contract version ID to migrate the plans to.\n\nRequired."
      },
      "schedule_migration_type": {
          "description": "Specifies how existing schedules should be migrated.",
          "x-release-info": {
              "releaseVersion": {
                  "major": 2,
                  "minor": 4
              },
              "changeType": "ADD_FIELD"
          },
          "type": "string",
          "enum": [
              "SCHEDULE_MIGRATION_TYPE_RECREATE_ALL_SCHEDULES_AND_GROUPS",
              "SCHEDULE_MIGRATION_TYPE_PRESERVE_SCHEDULES_IF_NO_GROUP_CHANGES"
          ],
          "default": "SCHEDULE_MIGRATION_TYPE_RECREATE_ALL_SCHEDULES_AND_GROUPS",
          "x-enum-value-descriptions": {
              "SCHEDULE_MIGRATION_TYPE_PRESERVE_SCHEDULES_IF_NO_GROUP_CHANGES": "When updating the Supervisor Contract version of a plan, existing schedules are preserved if either: * They are not part of a group and a schedule of the same event type is defined in the new Supervisor Contract code; or * They are part of a group and a group of the same name, size and order is defined in the new Supervisor Contract code. New schedules are only created if they are defined in the new Supervisor Contract code.",
              "SCHEDULE_MIGRATION_TYPE_RECREATE_ALL_SCHEDULES_AND_GROUPS": "When updating the Supervisor Contract version of a plan, all existing schedules will be deleted then recreated according to the Supervisor Contract code of the new product version. Any updates previously made to existing schedules will not be preserved. This is the default behaviour."
          }
      }
  }
}
It looks like the offending property is
"required": true
which comes from the original content. That property also shows a warning in Swagger editor (see screenshot). As stated in the Swagger documentation, the warning informs that "_Any sibling elements of a
$ref
are ignored. This is because
$ref
works by replacing itself and everything on its level with the definition it is pointing at._" However, the Pactflow validator fails ignoring those properties. Is there chance this can be handled by Pactflow transparently instead of producing a validation error? Is there any other way to address this issue on my side? Thanks.
m
hello! Just an FYI, this is a #CLS16AVEE question (it’s not a feature in the open source pact broker, which is what this channel is for)
It might be possible. If you remove the
required
property, do things work?
c
It works if I remove the
required: true
attribute. Wondering if there is a way Pactflow validator can ignore it. The problem I have is that the OAS document I got is huge and it would be nice if the Pactflow validator were more flexible.
@Matt (pactflow.io / pact-js / pact-go), after a lot of trial & error, I managed to address my issue and now Pactflow can read & parse the entire OAS file successfully. Looks like Pactflow validator crashes/complains when it runs into a node having
"$ref"
and
"required"
sibling attributes together. Per the OAS standard, "_Any sibling elements of a
$ref
are ignored. This is because
$ref
works by replacing itself and everything on its level with the definition it is pointing at._" More info this here . This is the sort of changes I have to do manually: file:///tmp/image.png Is there a chance of the Pactflow validator ignoring all
"required"
attributes whenever a sibling
"$ref"
attribute is present?