When I generate swagger UI documentation the path has an extra part that is not needed

Summary

The issue at hand involves generating Swagger UI documentation for an AWS API Gateway API, where the title specified in the OpenAPI YAML file disappears, and an extra part is added to each path in the generated HTML. The extra path part is not present in the original OpenAPI spec nor the exported spec, and its origin is unclear. The goal is to correct the title disappearance and remove the unnecessary path segment.

Root Cause

The root cause of this issue can be attributed to the following:

  • Mismatch between OpenAPI YAML and exported JSON: The title discrepancy between the OpenAPI YAML file and the exported JSON file may be due to inconsistent configuration or versioning issues.
  • Swagger UI configuration: The extra path part may be a result of incorrect Swagger UI settings or default configurations that are not properly overridden.

Why This Happens in Real Systems

This issue occurs in real systems due to:

  • Complexity of API Gateway configurations: AWS API Gateway has a multitude of configuration options, making it easy to overlook or misconfigure certain settings.
  • Versioning and compatibility issues: Differences in OpenAPI specification versions or incompatible configurations can lead to unexpected behavior.
  • Default settings and assumptions: Swagger UI and API Gateway may have default settings or assumptions that do not align with the expected behavior, leading to unexpected path segments.

Real-World Impact

The impact of this issue includes:

  • Inaccurate documentation: The disappearance of the title and addition of extra path parts can lead to confusing and inaccurate documentation, making it difficult for developers to understand and use the API.
  • Integration issues: The incorrect path segments can cause integration problems with other systems or services that rely on the API.

Example or Code (if necessary and relevant)

import json

# Example OpenAPI YAML file
openapi_yaml = """
openapi: 3.0.0
info:
  title: My API
  version: 1.0.0
paths:
  /v1:
    get:
      summary: Get data
      responses:
        '200':
          description: Data retrieved successfully
"""

# Exported JSON file
exported_json = """
{
  "openapi": "3.0.0",
  "info": {
    "title": "AWS API Gateway API",
    "version": "1.0.0"
  },
  "paths": {
    "/communities-api-openapi/v1": {
      "get": {
        "summary": "Get data",
        "responses": {
          "200": {
            "description": "Data retrieved successfully"
          }
        }
      }
    }
  }
}
"""

How Senior Engineers Fix It

Senior engineers can fix this issue by:

  • Verifying OpenAPI YAML and exported JSON configurations: Ensure that the title and path configurations are consistent between the OpenAPI YAML file and the exported JSON file.
  • Checking Swagger UI settings: Review Swagger UI settings to ensure that they are properly configured to override default settings and remove unnecessary path segments.
  • Using API Gateway configuration options: Utilize API Gateway configuration options to customize the API endpoint and remove the extra path part.

Why Juniors Miss It

Junior engineers may miss this issue due to:

  • Lack of experience with API Gateway configurations: Inexperience with AWS API Gateway and OpenAPI specifications can lead to overlooking critical configuration settings.
  • Insufficient understanding of Swagger UI: Limited knowledge of Swagger UI settings and configurations can result in inability to customize the documentation.
  • Failure to test and verify: Inadequate testing and verification of the API documentation can lead to undetected issues and inaccurate documentation.