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

Hack around limitation that prevents $ref: ...s from having siblings #81

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

gnidan
Copy link
Member

@gnidan gnidan commented Feb 6, 2024

For any schema that defines a $ref property alongside any other properties, docusaurus-json-schema-plugin currently loses all other properties and treats the schema as just the $ref'd other schema itself. This is because docusaurus-json-schema-plugin uses the now-unmaintained @stoplight/json-ref-resolver, which is stuck on the old JSON Schema drafts 4-7 semantics. (In those older drafts, this behavior was correct.)

To work around this issue:

  • Expand the existing schema preprocessing logic to detect all $ref's with siblings

  • For each such case, replace the { $ref: "...", ...props } with that $ref moved into an available schema composition keyword. (e.g., it might become { ...props, allOf: [{ $ref: "..." }] }).

  • Throw an error if the schema uses all three composition keywords and there's no place for this weird unnecessary composition. (This seems quite unlikely, though)

  • Override docusaurus-json-schema-plugin's rendering to detect this preprocessed "unnecessary composition" and treat it as a special-case apart from the normal way it presents lists of composed schemas.

  • When a schema composition is used with only one item, treat it as representing the extension of a base schema, and present it as such.

  • Present purely annotative extensions with less visual clutter (like, for when a schema is just { $ref: "...", description: "..." }

Screenshot 2024-02-06 at 00 01 51

For any schema that defines a $ref property alongside any other
properties, docusaurus-json-schema-plugin currently loses all other
properties and treats the schema as just the $ref'd other schema

This is because docusaurus-json-schema-plugin uses the now-unmaintained
@stoplight/json-ref-resolver, which is stuck on the old JSON Schema
drafts 4-7 semantics.

(In those older versions, this behavior was correct.)

To work around this issue:
- Expand the existing schema preprocessing logic to detect all
  $ref's with siblings

- For each such case, replace the `{ $ref: "...", ...props }` with that
  $ref moved into an available schema composition keyword.
  (e.g., it might become `{ ...props, allOf: [{ $ref: "..." }] }`).

- Throw an error if the schema uses all three composition keywords and
  there's no place for this weird unnecessary composition.
  (This seems quite unlikely, though)

- Override docusaurus-json-schema-plugin's rendering to detect this
  preprocessed "unnecessary composition" and treat it as a special-case
  apart from the normal way it presents lists of composed schemas.

- When a schema composition is used with only one item, treat it as
  representing the extension of a base schema, and present it as such.

- Present purely annotative extensions with less visual clutter (like,
  for when a schema is just `{ $ref: "...", description: "..." }`
@gnidan gnidan merged commit 04490ed into main Feb 6, 2024
4 checks passed
@gnidan gnidan deleted the refs-with-siblings branch February 6, 2024 05:05
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

Successfully merging this pull request may close these issues.

1 participant