package
1.18.9
Repository: https://github.com/grokify/spectrum.git
Documentation: pkg.go.dev

# README

Spectrum OpenAPI 3 Inspect, Modify & Compare

Docs

Spectrum openapi3edit is a library to assist in inspecting and modifying OpenAPI specs.

OpenAPI specifications can be large and have many endpoints which can make it difficult to manage. Additionally, some services may consist of many specs created by different people, teams and software, so some ability to make various specs consistent is desirable, especially when the individual specs need to be merged into a master spec.

Key Features include:

  • Inspect: Various functions to examine aspects of a OpenAPI 3 spec including OperationIDs, paths, endpoint, schemas, tags, etc.
  • Modify: Ability to modify various properties programmatically.
  • Intersection: Ability to compare two specs and show the overlap.

Usage

Steps for clean merging of multiple specs.

  1. Examine all specs for consistent operationIds and tags
  2. Ensure that all specs can be merged to common server base URL and paths
  3. Optionally delete endpoint security from each spec and add it to merged spec
  4. Check / deletee overlapping operationIDs, endpoints (method+path) and schema components
  5. Validate resulting spec

Inspect & Modify

Use SpecMoreModifyMulti and SpecMoreModifyMultiOpts to handle to inspect and modify mulitple files.

Compare

Use openapi3edit.SpecsIntersection()

// spec1 and spec2 are *github.com/getkin/kin-openapi/openapi3.Swagger
intersectionData := openapi3edit.SpecsIntersection(spec1, spec2)
intersectionData.Sort()

Delete

After running intersection, you can use the resulting data to delete those items from a spec using SpecDeleteProperties. Be sure to validate afterwards.

This is useful when merging to specs with an overlap. To check for cleanliness of merging, you can:

  1. run an intersection
  2. delete the intersection from one of the sepcs and ensures it still validates
  3. merge the specs

Examples

Add Bearer Token Auth

openapi3edit.SecuritySchemeAddBearertoken(
    spec, "", "",
    []string{},
    []string{
        "Authentication",
    },
)

# Packages

No description provided by the author

# Functions

No description provided by the author
FuncSchemaRefModFromSchemaKeyMod takles a function for modifying schema keys and turns it into a function for modifying JSON schema pointers for schemas keys.
No description provided by the author
No description provided by the author
No description provided by the author
NewTagsSimple returns a `Tags` struct that can be assigned to `openapi3.Spec.Tags`.
PathTemplateParamMod takes a URL path with templated parameters like `{pet_id}`.`.
No description provided by the author
SchemaRefModifyRefsRx modifies Schema reference schema pointers that match the supplied `*regexp.Regexp` with the replacement string.
SortParameters sorts parameters according to an input name list.
SpecMoreModifyMulti is used to perform multiple updates on an OpenAPI 3 spec.
TagsOrder creates a list of ordered tags based on an input set and explitcit sort order.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
#nosec G101.
No description provided by the author
No description provided by the author

# Variables

No description provided by the author

# Structs

OperationEdit is used for two purposes: (a) to store path and method information with the operation and (b) to provide a container to organize operation related functions.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
TagsModifyOpts is used with `SpecEdit.TagsModifyMore()`.