Skip to content

Capability to copy (deep) nodes from one target to another target #121

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

Open
ThomasRooney opened this issue Feb 27, 2025 · 3 comments
Open
Milestone

Comments

@ThomasRooney
Copy link

ThomasRooney commented Feb 27, 2025

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.

@lornajane
Copy link
Contributor

This is a good use case! I think there might also be a wider consideration here about how to use parts of the OpenAPI description (in its current state at the time the action runs) as inputs to actions.

@ralfhandl ralfhandl added this to the Release 2.0 milestone Feb 28, 2025
@kevinswiber
Copy link

There's a lot of overlap with #30 and #32.

@sjoubert
Copy link

Another similar use case to 1. (but with dynamic destination based on the target) would be to duplicate content entries for requestBody or responses. Consider an API that wants to support both JSON and YAML (input and/or output), currently we have to do:

paths:
  /item:
    post:
      requestBody:
        content:
          application/json:
            $ref: '#/components/schemas/Item'
          application/yaml:
            $ref: '#/components/schemas/Item'

But this means we may forget to add the yaml duplicate on new paths or methods. This would be nice to only specify one:

paths:
  /item:
    post:
      requestBody:
        content:
          application/json:
            $ref: '#/components/schemas/Item'

and overlay an action to duplicate all application/json into application/yaml at once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants