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

Referring object tamper other objects through referenced one #2419

Closed
vZ2JEZsZW opened this issue Sep 29, 2023 · 5 comments · Fixed by #2481
Closed

Referring object tamper other objects through referenced one #2419

vZ2JEZsZW opened this issue Sep 29, 2023 · 5 comments · Fixed by #2481
Assignees
Labels
p/high t/bug Something isn't working triaged

Comments

@vZ2JEZsZW
Copy link

description and examples of referring objects discarded in favor of values spreading from other objects referring same target.

Steps to Reproduce:

# file2.yaml
referenced: { type: string }
object:
    allOf:
        -   type: object
            properties:
                AAAAA:
                    $ref: '#/referenced'
                    description: AAAAA
                    examples: [AAAAA]
                BBBBB:
                    $ref: '#/referenced'
                    description: BBBBB
                    examples: [BBBBB]
# file1.yaml
paths:
    /operation:
        post:
            summary: operation
            requestBody:
                required: true
                content:
                    application/json:
                        schema: {$ref: 'file2.yaml#/object'}
            operationId: operationId
            security: [ ]
servers: [ url: 'http://example.com' ]
openapi: 3.1.0
info:
    title: Test
    version: version

Resulting documentation: BBBBB gets irrelevant description and examples from AAAAA
stoplight

Version used: 7.13.1

@chohmann chohmann added t/bug Something isn't working triaged and removed t/bug Something isn't working triaged labels Nov 3, 2023
@EdVinyard EdVinyard added t/bug Something isn't working triaged p/high labels Nov 10, 2023
@matthewmurphy
Copy link

Here's another example of the problem:

openapi.yaml:

openapi: 3.1.0
info:
  title: Test
  version: version
paths:
  /operation:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                AAAAA:
                  $ref: 'referenced.yaml'
                  description: AAAAA
                  examples:
                    - AAAAA
                BBBBB:
                  $ref: 'referenced.yaml'
                  # If description is commented out, it's displayed as AAAAA
                  description: BBBBB
                  # Example is displayed as AAAAA
                  examples:
                    - BBBBB

referenced.yaml:

title: referenced
type: string

In this example the response body is inline rather than ref'ed and does not include the allOf to show combiners are not part of the problem. referenced is still in its own file and the problem does not appear to exist if it's inline or a ref to a schema in the same file in the components section.

Results in:
image

@matthewmurphy matthewmurphy removed their assignment Nov 17, 2023
@brendarearden brendarearden self-assigned this Nov 20, 2023
@brendarearden
Copy link
Contributor

@vZ2JEZsZW I am currently troubleshooting this and had a question: were you using elements dev portal when encountering this issue?
I am not able to reproduce in elements with the example provided due to elements using a single file and not two separate files.

@vZ2JEZsZW
Copy link
Author

were you using elements dev portal when encountering this issue? I am not able to reproduce in elements with the example provided due to elements using a single file and not two separate files.

I believe it's "stoplight elements" and in my case the spec was split in several files so was the minimal reproducible example I extracted. What follows is an html page which exhibits described behavior.

page.html

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>api</title>
    <script src="https://unpkg.com/@stoplight/elements@7.13.1/web-components.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/@stoplight/elements@7.13.1/styles.min.css">
</head>
<body>
    <elements-api apiDescriptionUrl="file1.yaml" router="hash" />
</body>
</html>

Yamls are same files from original post repeated for completeness.

file1.yaml

paths:
    /operation:
        post:
            summary: operation
            requestBody:
                required: true
                content:
                    application/json:
                        schema: {$ref: 'file2.yaml#/object'}
            operationId: operationId
            security: [ ]
servers: [ url: 'http://example.com' ]
openapi: 3.1.0
info:
    title: Test
    version: version

file2.yaml

referenced: { type: string }
object:
    allOf:
        -   type: object
            properties:
                AAAAA:
                    $ref: '#/referenced'
                    description: AAAAA
                    examples: [AAAAA]
                BBBBB:
                    $ref: '#/referenced'
                    description: BBBBB
                    examples: [BBBBB]

@brendarearden
Copy link
Contributor

@vZ2JEZsZW I have merged in a fix for this issue and the fix is available in elements version 7.16.1

While I was working on this fix, I realized that part of the issue you are experiencing is due to having invalid reference siblings. As of oas 3.1.0 the only fields allowed in a reference object are $ref, description and summary. To ensure your examples are correctly maintained, you would need to update your file2.yaml to something like this:

referenced: { type: string }
object:
  allOf:
    - type: object
      properties:
        AAAAA:
          allOf:
            - $ref: "#/referenced"
              description: AAAAA
            - examples: [AAAAA]
        BBBBB:
          allOf:
            - $ref: "#/referenced"
              description: BBBBB
            - examples: [BBBBB]

@vZ2JEZsZW
Copy link
Author

That's good to hear you fixed this!

As of oas 3.1.0 the only fields allowed in a reference object are $ref, description and summary.

I will take that into account, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p/high t/bug Something isn't working triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants