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.0 support: additionalProperties: false adds additionalProp1 to samples #9022

Closed
adavis444 opened this issue Jul 16, 2023 · 2 comments · Fixed by #9023
Closed
Assignees

Comments

@adavis444
Copy link
Contributor

Q&A

  • OS: macOS
  • Browser: chrome
  • Version: Version 114.0.5735.198 (Official Build) (arm64)
  • Method of installation: git & npm
  • Swagger-UI version: v5.1.1/89f04d3 (latest master)
  • Swagger/OpenAPI version: OpenAPI 3.1.0 - Not an issue in OpenAPI 3.0.x

Content & configuration

Example OpenAPI definition

Minimal example that demonstrates the issue for "additionalProperties": false with OpenAPI 3.1.0

{
  "openapi": "3.1.0",
  "info": {
    "title": "foo",
    "version": "0.1.0"
  },
  "paths": {
    "/": {
      "post": {
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "bar": {
                    "type": "string"
                  }
                },
                "additionalProperties": false,
                "type": "object",
                "title": "Foo"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response"
          }
        }
      }
    }
  }
}

Describe the bug you're encountering

When the value of openapi in the OpenAPI definition is 3.0.3, the sample body for a POST / request is correctly rendered as

{
  "bar": "string"
}

However, when the value of openapi is 3.1.0, the sample body for a POST / request is incorrectly rendered as

{
  "bar": "string",
  "additionalProp1": {}
}

To reproduce...

Steps to reproduce the behavior:

  1. Follow the instructions in https://github.com/swagger-api/swagger-ui/blob/master/docs/development/setting-up.md#steps to set up dev environment
  2. Save the above OpenAPI definition to dev-helpers/examples/openapi.json
  3. Follow the instructions in https://github.com/swagger-api/swagger-ui/blob/master/docs/development/setting-up.md#using-your-own-local-api-definition-with-local-dev-build to modify dev-helpers/dev-helper-initializer.js by replacing https://petstore.swagger.io/v2/swagger.json with ./examples/openapi.json
  4. Go to http://localhost:3200/ in browser
  5. See error in sample request body: additionalProp1 field is present, violating "additionalProperties": false in OpenAPI definition

Modifying the value of openapi to 3.0.3 (or any existing 3.0.x version) in dev-helpers/examples/openapi.json will display a correct sample.

Expected behavior

The sample request body for OpenAPI 3.1.0+ should not generate additional properties when "additionalProperties": false is present, instead maintaining consistency with OpenAPI 3.0.x samples.

Screenshots

Correct sample with OpenAPI 3.0.3:
image

Incorrect sample with OpenAPI 3.1.0:
image

Additional context or thoughts

Introduced in the implementation of #8577 in the PR #8910 in
src/core/plugins/json-schema-2020-12/samples-extensions/fn/main.js
with change from if (additionalProperties === true) { to if (isBooleanJSONSchema(additionalProperties)) {.

@char0n
Copy link
Member

char0n commented Jul 24, 2023

Hi @adavis444,

It's legit, I've introduced the bug myself, thanks for providing a PR for it ;]

char0n pushed a commit that referenced this issue Jul 24, 2023
…0-12 (#9023)

This change is specific to JSON Schema 2020-12 and OpenAPI 3.1.0.

Refs #9022
@char0n
Copy link
Member

char0n commented Jul 24, 2023

Fixed in #9023

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