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

Using readOnly and required fails #289

Closed
Linuus opened this issue Nov 6, 2020 · 3 comments
Closed

Using readOnly and required fails #289

Linuus opened this issue Nov 6, 2020 · 3 comments

Comments

@Linuus
Copy link

Linuus commented Nov 6, 2020

Hi!

I have a schema where an attribute type is marked as readOnly. It cannot be set or updated but it is always returned.
Now, to make Committee validate (in my tests) that this attribute is always returned, I need to also mark it as required. But when I mark it as required Committee throws an InvalidRequest error (when calling assert_schema_conform) if I don't pass it in my PATCH request in my tests.

It should actually fail if I pass the type attribute in the PATCH request.

Or am I wrong here? 🤔

@ota42y
Copy link
Member

ota42y commented Nov 7, 2020

Could you tell me a little more about it?

  • What kind of Schema definition is it?
  • What kind of request are you sending

@Linuus
Copy link
Author

Linuus commented Nov 9, 2020

This is a stripped down version of the schema (OpenAPI 3).

---
openapi: 3.0.0
info:
  version: 1.0.0
  title: Foobar API
  description: ''
servers:
- url: https://api.example.com
  description: ''
security: []
paths:
  "/foobars":
    get:
      summary: Retrieves the foobars.
      responses:
        "200":
          description: success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Foobar"
  "/foobars/{id}":
    patch:
      parameters:
        - $ref: "#/components/parameters/id"
      requestBody:
        "$ref": "#/components/requestBodies/updateFoobar"
      responses:
        "204":
          description: no content
components:
  parameters:
    id:
      name: id
      in: path
      required: true
      schema:
        type: integer
        description: The ID of the record.
        readOnly: true
      description: The ID of the record.
  schemas:
    Foobar:
      type: object
      properties:
        type:
          type: string
          enum:
            - foo
            - bar
          description: The type of the foobar.
          readOnly: true
      required:
        - type
  requestBodies:
    updateFoobar:
      content:
        application/json:
          schema:
            type: object
            properties:
              foobar:
                $ref: "#/components/schemas/Foobar"

So, in this case, the type field is both readOnly (cannot be set) and also required as in, it will always be returned by the server (I want Committee to validate that I always return the type field).

So, the since the type field is readOnly it shouldn't be required for the PATCH. If you paste the above schema at: https://editor.swagger.io/ for instance, you can see that the type field is marked as required in responses, but not shown in the PATCH request.

@ota42y
Copy link
Member

ota42y commented Nov 14, 2020

The committee doesn't support readOnly / writeOnly yet. 😢
(So I close and move to this issue #276)

@ota42y ota42y closed this as completed Nov 14, 2020
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

No branches or pull requests

2 participants