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

[OpenAPI 3.1] Example value is not generated for nested objects that are referenced via allOf #9941

Closed
hkosova opened this issue May 15, 2024 · 11 comments

Comments

@hkosova
Copy link
Contributor

hkosova commented May 15, 2024

Q&A (please complete the following information)

  • OS: macOS 13.6.7
  • Browser: Chrome latest
  • Method of installation: standalone Swagger UI (5.17.9), also https://editor-next.swagger.io (UI v. 5.17.3)
  • Swagger-UI version: 5.17.9, 5.17.3
  • Swagger/OpenAPI version: OpenAPI 3.1 only

Ref swagger-api/swagger-js#3520

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.1.0
info:
  title: Example generation test
  version: 1.0.0
paths:
  /foo:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Foo'

components:
  schemas:
    Foo:
      type: object
      properties:
        bar:
          allOf:
            - $ref: '#/components/schemas/Bar'
    
    Bar:
      type: object
      properties:
        a:
          type: integer
          example: 123
        b:
          type: string
          example: hello

Describe the bug you're encountering

The issue may (or may not) be related to #8374.

On the "Example Value" tab, the bar value appears empty object "bar": {} instead of an actual object generated from its schema "bar": {"a": 123, "b": "hello"}. This happens for properties that reference their schema using allOf+$ref instead of just $ref.

The property schema on the "Schema" tab appears correctly though, and shows all fields defined in the referenced schema.

The issue exists for OpenAPI 3.1 definitions and does NOT exist for OpenAPI 3.0 and 2.0.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor-next.swagger.io
  2. Paste the definition provided above.
  3. Expand the GET /foo operation and examine the "Example Value".

Actual result:

{
  "bar": {}
}

Expected result:

{
  "bar": {
    "a": 123,
    "b": "hello"
  }
}
  1. Replace openapi: 3.1.0 with openapi: 3.0.0.
  2. Example "Example Value" again.

=> Now the example value is correct and includes the nested fields.

Screenshots

Additional context or thoughts

Looks like the correctness of the Example Value depends on whether the user expands the operation or schema first? If I first fully expand the schema under "Schemas" at the bottom, then the Example Value inside the operation is generated correctly.

weird

@char0n
Copy link
Member

char0n commented May 16, 2024

Hi @hkosova,

Nice to see you here again ;]

We're looking into the issue. Thanks for the report.

@glowcloud
Copy link
Contributor

I can confirm this is a regression in Swagger Client.

This works properly in Swagger UI version 5.15.2 and stops working in 5.16.0. We updated the Swagger Client version from 3.26.8 to 3.27.0 and there were changes to dereferencing: swagger-api/swagger-js#3472, so it looks like the regression was caused by that.

@char0n
Copy link
Member

char0n commented May 16, 2024

@glowcloud can you constructor minimal reproducibe fixture with expected result and current result?

@glowcloud
Copy link
Contributor

glowcloud commented May 16, 2024

Looks like it can be reproduced without the reference inside of allOf:

openapi: 3.1.0
info:
  title: Example generation test
  version: 1.0.0
paths:
  /foo:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Foo'
components:
  schemas:
    Foo:
      type: object
      properties:
        bar:
          allOf:
            - type: object
              properties:
                a:
                  type: integer

Here's the schema inside of response with the allOf keyword:
Screenshot 2024-05-16 at 10 01 44

and under schemas:
Screenshot 2024-05-16 at 09 59 45

@char0n
Copy link
Member

char0n commented May 17, 2024

Associated upstream swagger-js issue has been created in swagger-api/swagger-js#3520

@char0n char0n self-assigned this May 17, 2024
@dominikforal
Copy link

We're encountering the same issue with our documentation. This is a high priority matter as a significant portion of our documentation is affected.

@char0n
Copy link
Member

char0n commented May 21, 2024

We already have an upstream regression remediation in swagger-api/swagger-js#3521

ETA in SwaggerUI during today.

@char0n
Copy link
Member

char0n commented May 21, 2024

Upstream fix released in swagger-client@3.28.1

@char0n
Copy link
Member

char0n commented May 21, 2024

Addressed for SwaggerUI in #9950

@char0n
Copy link
Member

char0n commented May 21, 2024

Released as https://github.com/swagger-api/swagger-ui/releases/tag/v5.17.12

@char0n char0n closed this as completed May 21, 2024
@hkosova
Copy link
Contributor Author

hkosova commented May 21, 2024

Thanks for the quick fix @char0n, @glowcloud!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants