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

Support readOnly, writeOnly (>= Draft 7) #55

Closed
ahx opened this issue Nov 26, 2019 · 4 comments
Closed

Support readOnly, writeOnly (>= Draft 7) #55

ahx opened this issue Nov 26, 2019 · 4 comments

Comments

@ahx
Copy link
Contributor

ahx commented Nov 26, 2019

The readOnly and writeOnly keywords (see specification (Draft 7)) make validation behave differently in the context of a write or read operation.

Unfortunately this does not seem to be covered by JSON-Schema-Test-Suite.

I found one (Java) library that supports this.

@davishmcclurg
Copy link
Owner

The specification doesn't seem to get into how these keywords relate to validating data, though I can see how specifying a validation context could be useful. I don't plan on working on this myself, but PRs are always welcome.

@ahx
Copy link
Contributor Author

ahx commented Oct 15, 2020

There is an example how one could handle readOnly: true via the before_property_validation option that was added in #77 in one of the tests. This covers my use case for readOnly.

@ahx
Copy link
Contributor Author

ahx commented Nov 16, 2020

If someone is interested in this as well: Actually using the added hooks to hack in readOnly behaviour did not work in my case, because is not called on sub-schemas used inside allOf etc. :|
Another, probably better, approach could be a custom keyword. There already is some support for custom keywords, but I cannot use that to hack readOnly.

davishmcclurg added a commit that referenced this issue Jul 29, 2023
This adds support for OpenAPI 3.0 documents and schemas. There's no
published meta schema or dialect that I could find, so the meta schema
refs into the published document schema instead. Everything is based off
of draft 4.

The keywords additions are `nullable` (implemented in `type`),
`readOnly`, and `writeOnly`. There are also a couple new formats (`byte`
and `binary`).

`readOnly` and `writeOnly` are implemented with a new option called
`access_mode` that triggers errors for invalid access, ie a `writeOnly`
property is present in "read" access mode. It also removes keys from
`required` depending on the specified mode. These features are
implemented in draft 2020-12 because they seemed like they might be
useful elsewhere and they're off by default.

`nullable` just adds "null" to the allowed `type` array. You'd probably
get better errors with an actual `Nullable` keyword class, but it didn't
seem worth it at this point.

Related:

- #55
davishmcclurg added a commit that referenced this issue Jul 31, 2023
Features:

- Draft 2020-12 support
- Draft 2019-09 support
- Output formats
- Annotations
- OpenAPI 3.1 schema support
- OpenAPI 3.0 schema support
- `insert_property_defaults` in conditional subschemas
- Error messages
- Non-string schema and data keys

See individual commits for more details.

Closes:

- #27
- #44
- #55
- #91
- #94
- #116
- #123
davishmcclurg added a commit that referenced this issue Aug 1, 2023
This adds support for OpenAPI 3.0 documents and schemas. There's no
published meta schema or dialect that I could find, so the meta schema
refs into the published document schema instead. Everything is based off
of draft 4.

The keywords additions are `nullable` (implemented in `type`),
`readOnly`, and `writeOnly`. There are also a couple new formats (`byte`
and `binary`).

`readOnly` and `writeOnly` are implemented with a new option called
`access_mode` that triggers errors for invalid access, ie a `writeOnly`
property is present in "read" access mode. It also removes keys from
`required` depending on the specified mode. These features are
implemented in draft 2020-12 because they seemed like they might be
useful elsewhere and they're off by default.

`nullable` just adds "null" to the allowed `type` array. You'd probably
get better errors with an actual `Nullable` keyword class, but it didn't
seem worth it at this point.

Related:

- #55
davishmcclurg added a commit that referenced this issue Aug 1, 2023
Features:

- Draft 2020-12 support
- Draft 2019-09 support
- Output formats
- Annotations
- OpenAPI 3.1 schema support
- OpenAPI 3.0 schema support
- `insert_property_defaults` in conditional subschemas
- Error messages
- Non-string schema and data keys

See individual commits for more details.

Closes:

- #27
- #44
- #55
- #91
- #94
- #116
- #123
@davishmcclurg davishmcclurg mentioned this issue Aug 1, 2023
davishmcclurg added a commit that referenced this issue Aug 19, 2023
This adds support for OpenAPI 3.0 documents and schemas. There's no
published meta schema or dialect that I could find, so the meta schema
refs into the published document schema instead. Everything is based off
of draft 4.

The keywords additions are `nullable` (implemented in `type`),
`readOnly`, and `writeOnly`. There are also a couple new formats (`byte`
and `binary`).

`readOnly` and `writeOnly` are implemented with a new option called
`access_mode` that triggers errors for invalid access, ie a `writeOnly`
property is present in "read" access mode. It also removes keys from
`required` depending on the specified mode. These features are
implemented in draft 2020-12 because they seemed like they might be
useful elsewhere and they're off by default.

`nullable` just adds "null" to the allowed `type` array. You'd probably
get better errors with an actual `Nullable` keyword class, but it didn't
seem worth it at this point.

Related:

- #55
davishmcclurg added a commit that referenced this issue Aug 19, 2023
Features:

- Draft 2020-12 support
- Draft 2019-09 support
- Output formats
- Annotations
- OpenAPI 3.1 schema support
- OpenAPI 3.0 schema support
- `insert_property_defaults` in conditional subschemas
- Error messages
- Non-string schema and data keys
- Schema bundling

See individual commits for more details.

Closes:

- #27
- #44
- #55
- #91
- #94
- #116
- #123
- #136
davishmcclurg added a commit that referenced this issue Aug 20, 2023
This adds support for OpenAPI 3.0 documents and schemas. There's no
published meta schema or dialect that I could find, so the meta schema
refs into the published document schema instead. Everything is based off
of draft 4.

The keywords additions are `nullable` (implemented in `type`),
`readOnly`, and `writeOnly`. There are also a couple new formats (`byte`
and `binary`).

`readOnly` and `writeOnly` are implemented with a new option called
`access_mode` that triggers errors for invalid access, ie a `writeOnly`
property is present in "read" access mode. It also removes keys from
`required` depending on the specified mode. These features are
implemented in draft 2020-12 because they seemed like they might be
useful elsewhere and they're off by default.

`nullable` just adds "null" to the allowed `type` array. You'd probably
get better errors with an actual `Nullable` keyword class, but it didn't
seem worth it at this point.

Related:

- #55
davishmcclurg added a commit that referenced this issue Aug 20, 2023
Features:

- Draft 2020-12 support
- Draft 2019-09 support
- Output formats
- Annotations
- OpenAPI 3.1 schema support
- OpenAPI 3.0 schema support
- `insert_property_defaults` in conditional subschemas
- Error messages
- Non-string schema and data keys
- Schema bundling

See individual commits for more details.

Closes:

- #27
- #44
- #55
- #91
- #94
- #116
- #123
- #136
@davishmcclurg
Copy link
Owner

Released in 2.0.0. Use access_mode option (read/write):

JSONSchemer.schema(schema).validate(data, :access_mode => 'read')

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