Skip to content

Render (complex) subelements in one of. Keep description on the property, do not copy it down. - #319

Closed
Xarno wants to merge 1 commit into
Authress-Engineering:release/2.4from
Xarno:rendererror
Closed

Xarno wants to merge 1 commit into
Authress-Engineering:release/2.4from
Xarno:rendererror

Conversation

@Xarno

@Xarno Xarno commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

If a pattern got into a one of it was not rendered. This change fixes the rendering.

Broken

Broken

Fixed

Fixed

Example openapi file to show the problem:

{
  "openapi": "3.1.0",
  "info": {
    "title": "Nullable object with patternProperties",
    "version": "1.0",
    "description": "The two request bodies differ only in the type of `localized`: `object` vs. `[\"object\", \"null\"]`. Both must show the `<pattern: [a-z]{2}>` key with its fields, and the description once, on `localized` itself."
  },
  "paths": {
    "/object": {
      "post": {
        "summary": "localized: type object (reference, renders correctly)",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "localized": {
                    "type": "object",
                    "description": "Translations, keyed by language code.",
                    "patternProperties": {
                      "[a-z]{2}": { "$ref": "#/components/schemas/Translation" }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": { "204": { "description": "No content" } }
      }
    },
    "/nullable-object": {
      "post": {
        "summary": "localized: type [object, null] (pattern key missing, description repeated on each option)",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "localized": {
                    "type": ["object", "null"],
                    "description": "Translations, keyed by language code.",
                    "patternProperties": {
                      "[a-z]{2}": { "$ref": "#/components/schemas/Translation" }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": { "204": { "description": "No content" } }
      }
    }
  },
  "components": {
    "schemas": {
      "Translation": {
        "type": "object",
        "properties": {
          "subject": { "type": "string" },
          "body": { "type": "string" }
        }
      }
    }
  }
}

@Xarno

Xarno commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Fixes #320

Comment thread src/utils/schema-utils.js
obj['::circular'] = !!schema.circularReference;
obj['::type'] = 'object';
// The description belongs to the property itself, not to each of its type options
obj['::title'] = schema.title || '';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the fix here, but all those other changes don't look correct to me. If we are setting the title, I don't see why we wouldn't set all the other ones.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which other ones do you mean? The idea was to move the description up and not have them repeated on any element of the "one of".

Image

@wparad wparad Nov 6, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your example is for primitive type array but you are also changing the complex types handling, why?

That's what I'm asking.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #300 i had the very primitive type int.
I try to word it differently "why". The property "localized" has a description. It has sub properties, which can be direct, one of, any of. The description (and related texts) belong to it.
If number one of the 'one of' has a different description it should / would show that, not copy over the top level description. Same for other relationships.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's take a step back. I'm just saying your example spec is just the primativetype path as the one with the issue. While I can fully believe other flows also have an issue, let's just focus on one of these in this PR. I propose let's solve the localize multiple type for privative types rather than trying to solve the one of or any of here, and handle them in a follow up PR if you need those fixed too

This is the best way to make sure I can review this and get it in. Rather than changing all of them and needing to reason about more than one flow at a time. Does that make sense?

@wparad wparad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_

@Xarno

Xarno commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Superseeded by #321, which handles the rendering only.
I look into the Description placement in a separate commit.

@Xarno Xarno closed this Nov 9, 2026
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.

2 participants