🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

github.com/patricksimonian/k8s-mock-server-generator/openapi-ir-processor

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/patricksimonian/k8s-mock-server-generator/openapi-ir-processor

v0.0.0-20250317212349-33f68a411cbe
Version published
Created

OpenAPI IR Processor

This Go program, openapi-ir-processor, transforms a fully dereferenced OpenAPI (Swagger 2.0) specification into an intermediate representation (IR) suitable for further processing by other tools, such as code generators.

Features

  • OpenAPI to IR Conversion: Parses a dereferenced OpenAPI specification and converts it into a structured IR.
  • Endpoint Extraction: Extracts detailed information about each API endpoint, including method, path, parameters, and responses.
  • Model Processing: Processes and stores data models defined in the OpenAPI specification.
  • Parameter Handling: Merges global and operation-level parameters and converts them into a simplified IR format.
  • Response Handling: Converts API responses, resolving schema references to models.
  • Path Variable Conversion: Converts OpenAPI path variables (e.g., {id}) to Express-style variables (e.g., :id).
  • Operation ID Generation: Generates fallback operation IDs if they are missing in the specification.

Prerequisites

  • Go 1.16+: Ensure you have Go installed and configured.
  • Dereferenced OpenAPI Specification: This program requires a fully dereferenced OpenAPI (Swagger 2.0) JSON file. You can use tools like swagger-spec-dereferencer to prepare your specification.

Installation

  • Clone the Repository:

    git clone <repository_url>
    cd openapi-ir-processor
    
  • Build the Program:

    go build
    

Usage

  • Prepare Your OpenAPI Specification: Ensure you have a fully dereferenced OpenAPI specification file (e.g., dereferenced_swagger.json).

  • Run the Program: Provide the path to your dereferenced OpenAPI specification as a command-line argument.

    ./openapi-ir-processor dereferenced_swagger.json
    
  • Output: The program will output the extracted endpoint information to the console, including method, path, operation ID, summary, description, tags, parameters, and responses. Optionally it will also output the full IR as JSON.

    Example output:

    Endpoint: GET /api/v1/pets/:id (OperationID: get_api_v1_pets_{id})
      Summary: Get a pet by ID
      Description: Retrieves a pet based on the ID supplied
      Tags: [pets]
      Parameters:
        - "id" (path) required: true
      Responses:
        200: Successful operation, Schema: &{...}
    
    --- Full IR ---
    {
      "Title": "Petstore API",
      "Version": "1.0.0",
      "BasePath": "/api/v1",
      "Endpoints": [
        {
          "OperationID": "get_api_v1_pets_{id}",
          "Method": "get",
          "Path": "/api/v1/pets/:id",
          "Summary": "Get a pet by ID",
          "Description": "Retrieves a pet based on the ID supplied",
          "Tags": [
            "pets"
          ],
          "Parameters": [
            {
              "Name": "id",
              "In": "path",
              "Required": true,
              "Type": "",
              "Description": "",
              "Schema": null
            }
          ],
          "Responses": {
            "200": {
              "StatusCode": "200",
              "Description": "Successful operation",
              "Schema": {...}
            }
          }
        },
        ...
      ],
      "Models": {
        "Pet": {...}
      }
    }
    

Contributing

Contributions, improvements, and bug reports are welcome. Please open an issue or submit a pull request with your changes.

License

This project is licensed under the MIT License.

FAQs

Package last updated on 17 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts