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

Request Schema Validator issue when resolving Open API 3 $ref definitions #12405

Open
aka4rKO opened this issue Feb 16, 2022 · 1 comment
Open

Comments

@aka4rKO
Copy link

aka4rKO commented Feb 16, 2022

Description:

The APIM 4.0.0 currently has an issue of not being able to validate Open API 3 definitions when the schema validation is enabled.

After debugging the carbon-apimgt repo it was identified that the parameters/components referenced with $ref in the Open API 3 definitions are not getting resolved in the swagger-parser [1] library.

Example:

paths:
  /users/{userId}:
    get:
      summary: Returns a user by ID.
      parameters:
        - in: path
          name: userId
          required: true
          schema:
            type: integer
            format: int64
            minimum: 1
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'    # <-------
  /users:
    post:
      summary: Creates a new user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/User'      # <-------
      responses:
        '201':
          description: Created


This could be easily solved by passing the ParseOptions object into the OpenAPIParser.readContents() method with the ParseOptions.resolveFully set to true like below:

OpenAPIParser openAPIParser = new OpenAPIParser();
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolveFully(true);
SwaggerParseResult swaggerParseResult =
        openAPIParser.readContents(swagger, new ArrayList<>(), parseOptions);

The above fix too does not work due to an issue [2] in the swagger-parser version used in APIM 4.0.0

[1] https://github.com/swagger-api/swagger-parser
[2] swagger-api/swagger-parser#1579

Suggested solution:

The APIM 4.0.0 currently uses the swagger-parser version 2.0.20 and the fix for the aforementioned issue is fixed in 2.0.29 version, therefore the fix would be to upgrade the swagger-parser version used in APIM 4.0.0 to 2.0.29

Steps to reproduce:

  1. Publish an Open API 3 definition with referenced parameters/components ($ref)
  2. Enable schema validation
  3. Create an application
  4. Subscribe to the API
  5. Invoke the API with invalid referenced parameters/components to check if it gets validated
  6. If it does not get validated this issue is reproducible

Affected Product Version:

APIM 4.0.0


Optional Fields

Related Issues:

Suggested Labels:

Suggested Assignees:

@aka4rKO
Copy link
Author

aka4rKO commented Feb 28, 2022

Did not have to update the swagger-parser version to fix this issue. Adding Parse Options and setting resolve fully to true solves this issue.
Same as this PR https://github.com/wso2/carbon-apimgt/pull/10504/files

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

2 participants