Skip to content

Use existing content of OpenAPI as input to allow renaming/editing #121

Open
@ThomasRooney

Description

@ThomasRooney

The Actions Object has the ability to enable users to add/mutate/remove attributes on OpenAPI documents, but cannot handle the following scenarios:

  1. Renaming paths items

I.e. given a path on $.paths["/item"], move it to `$.paths["/newitem"]:

From

paths:
  /item:
    summary: 'The root resource'
    get:
      summary: 'Retrieve the root resource'
      ...

To:

paths:
  /newitem:
    summary: 'The root resource'
    get:
      summary: 'Retrieve the root resource'
      ...

Doing this via a full add/remove of the /item requires inlining the schema into the overlay, and thus makes it brittle: any overlay which overrides a path item in this way effectively nukes the ability for a source document to change any of the information in "/item".

  1. Extracting inline schemas into component schemas

Many OpenAPI frameworks produce inline json schemas for operations:

paths:
  /item:
    post:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - photoUrls
              properties:
                id:
                  type: integer
                  format: int64
                name:
                  type: string

Enabling an overlay to extract that inline schema and replace it with $ref: #/components/schemas/Item would enable a category of simplifications for downstream tooling.

Proposed change to the Actions Object

Fixed Fields
Field Name Type Description
target string REQUIRED A JSONPath expression selecting nodes in the target document.
description string A description of the action. [[CommonMark]] syntax MAY be used for rich text representation.
update Any If the target selects an object node, the value of this field MUST be an object with the properties and values to merge with the selected node. If the target selects an array, the value of this field MUST be an entry to append to the array.
remove boolean A boolean value that indicates that the target object or array MUST be removed from the the map or array it is contained in. The default value is false.
destination string A JSONPath expression selecting destination nodes in the target document. If set, this indicates that each node in the target expression (after applying the update) should be appended as a child to the destination node. If not set, the target is mutated in-place.

This would enable scenario 1 via

actions:
   - target: $.paths
     update: 
       "/newitem": {}
   - target: $.paths["/item"]
     destination: $.paths["/newitem"]
     remove: true

And scenario 2 via something similar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions