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

Broken readOnly + required combination #389

Closed
karlismelderis opened this issue Oct 6, 2020 · 7 comments
Closed

Broken readOnly + required combination #389

karlismelderis opened this issue Oct 6, 2020 · 7 comments

Comments

@karlismelderis
Copy link

Describe the bug
if prop is set to readOnly and required POST/PUT body validation is failing with "required item is missing"
(I'm at version 4.1.0)

To Reproduce
example schemas:

Item:
      allOf:
        - $ref: '#/components/schemas/id'
        - $ref: '#/components/schemas/name'

    id:
      properties:
        id:
          type: string
          readOnly: true
      required:
        - id

    name:
      properties:
        name:
          type: string
      required:
        - name

Actual behavior
Error is thrown:

{
  "errorCode": "required.openapi.validation",
  "message": "should have required property 'id'",
  "path": ".body.id"
}

Expected behavior
if prop is set to readOnly it's not checked in POST/PUT body

@cdimascio
Copy link
Owner

@karlismelderis I created two tests using the schema provided above. both work correctly. It will be great if you can take at the two tests and modify them to reproduce the result you are seeing. Alternatively, if it's easier for you, please create simple canonical example demonstrating the issue, and post it to a github. i'll definitely have a look. thanks!

@karlismelderis
Copy link
Author

ah missed comment. I will definitely try to create some code example for the case... or will find a bug in our schemas 🤔

@cdimascio
Copy link
Owner

Perhaps what u experienced is similar to #400. If so, I am working on a fix

@cdimascio
Copy link
Owner

@karlismelderis a number of improvements were made for readonly/required support via pr #414. they are available in v4.3.1 . please give it a try

@karlismelderis
Copy link
Author

👍 that's exactly my case.
we are reusing schemas a lot so api spec is full with allOf e.t.c.
I managed to narrow down to exact same case:

      "ItemDetails": {
        "allOf": [
          {
            "type": "object",
            "properties": {
              "createdBy": {
                "type": "object",
                "readOnly": true,
                "allOf": [
                  {
                    "type": "object",
                    "properties": {
                      "userId": {
                        "type": "string",
                        "description": "Unique user identifier, normally username"
                      },
                      "firstName": {
                        "type": "string",
                        "description": "Given Name"
                      },
                      "lastName": {
                        "type": "string",
                        "description": "Last (Family) Name"
                      }
                    }
                  }
                ]
              }
            },
            "required": [
              "createdBy"
            ]
          },
          {
            "properties": {
              "name": {
                "type": "string"
              }
            },
            "required": [
              "name"
            ]
          }
        ]
      }

@cdimascio
Copy link
Owner

@karlismelderis thanks for the example.
does this occur in 4.3.x?
also, you might try adding type: object to the last object in the allOf list i.e.

{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    }
  },
  "required": [
    "name"
  ]
}

@karlismelderis
Copy link
Author

👍 true. we missed some type: object in yml.

and issue is gone with latest version.
thank you for fixing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants