Hi My provider spec swagger results in this, which...
# pactflow
d
Hi My provider spec swagger results in this, which can be seen in the PactFlow broker
Copy code
someProxies array[object] or null
  name string or null
  enabled  boolean
  defaultSettlement integer<int32> or null
   Allowed values:
   1 2 null
My consumer contract contains this
Copy code
"someProxies ": [
      {
        "defaultSettlement": null,
        "enabled": true,
        "name": "My Settlement"
      }
However I get this error for the "defaultSettlement" Response body is incompatible with the response body schema in the spec file: must be equal to one of the allowed values Can anyone help figure out whats going wrong here? ps. I am using null, because I cant figure out a way cast to int due to the way the nullable definition is set up.
m
Can you please show the OAD file? The first code post isn't comprehensible to me
Ideally the OAD and pact file so we can review
d
Hopefully this is better
Copy code
{
  "openapi": "3.0.1",
  "info": {
    "title": "A Test Service",
    "version": "v1"
  },
  "paths": {
    ...
  },
  "components": {
    "schemas": {
      "CcySettings": {
        "type": "object",
        "properties": {          
          "MyProxies": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MyProxy"
            },
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "MyProxy": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "nullable": true
          },
          "enabled": {
            "type": "boolean"
          },
          "defaultSettlement": {
            "enum": [
              1,
              2
            ],
            "type": "integer",
            "format": "int32",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      
    }
  }
}
m
Thanks. I’m still figuring out why, but I’m able to make it work converting it to an OAS 3.1:
Copy code
openapi: 3.1.0
info:
  title: A Test Service
  version: v1
paths:
  /get:
    get:
      operationId: getAnimalByID
      responses:
        "200":
          description: successful operation
          content:
            "application/json":
              schema:
                $ref: '#/components/schemas/MyProxy'
components:
  schemas:
      MyProxy:
        type: object
        properties:
          name:
            type: 
              - string
              - 'null'
          enabled:
            type: boolean
          defaultSettlement:
            oneOf: 
              - type: 'null'
              - type: integer
                enum:
                  - 1
                  - 2
                format: int32
        additionalProperties: false
When using
nullable
in 3.0.1 I can’t get it to pass. It’s like nullable is being ignore somehow
Could you please raise a support ticket
(howtosupport)
s
Please create a ticket here with the issue details so that we can properly track the resolution and the PactFlow product support team will continue to work through it with you: https://support.smartbear.com/pactflow/message
m
OK managed to create an OAD that does work the way you need:
Copy code
openapi: 3.0.1
info:
  title: A Test Service
  version: v1
paths:
  /get:
    get:
      operationId: getAnimalByID
      responses:
        "200":
          description: successful operation
          content:
            "application/json":
              schema:
                $ref: '#/components/schemas/MyProxy'
components:
  schemas:
      MyProxy:
        type: object
        properties:
          name:
            type: string
            nullable: true
          enabled:
            type: boolean
          defaultSettlement:
            oneOf: 
              - type: integer
                enum:
                  - 1
                  - 2
                format: int32
              - type: object
                nullable: true
        additionalProperties: false
I suspect it relates to this: https://github.com/ajv-validator/ajv/issues/824 OAS 3 allows multiple types, but in OAS 3.0.x you can’t say an enum is of multiple types, I think is what it’s getting at
d
thanks heaps for looking into this, was driving me bonkers! I need to wait for a new release of Swashbuckle I think, to get 3.1
m
No probs!