Skip to content
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

bump overlay not merging parameters #580

Open
thim81 opened this issue Sep 10, 2024 · 1 comment
Open

bump overlay not merging parameters #580

thim81 opened this issue Sep 10, 2024 · 1 comment

Comments

@thim81
Copy link

thim81 commented Sep 10, 2024

Steps to reproduce

Openapi.yaml

openapi: 3.0.1
info:
  title: Datasource API
  description: API to work with Datasources.
  termsOfService: 'urn:tos'''
paths:
  /timeseries:
    get:
      operationId: searchTimeSeriesDefinitions
      summary: Search the time series definitions
      parameters:
        - name: searchPattern
          in: query
          description: Pattern to search time series definitions. Cannot be used at the same time as name parameter.
          required: false
          schema:
            type: string

overlays.yaml

overlay: 1.0.0
info:
  title: Structured Overlay
  version: 1.0.0
actions:
  - target: "$"   # Root of document
    update:
      paths:
        /timeseries:
          get:
            description: Retrieve a list of all time series definitions. This endpoint supports search and pagination.
            parameters:
              - name: searchPattern
                in: query
                description: A pattern used to search time series definitions.
                schema:
                  example: temp-

execute: bump overlay openapi.yaml overlays.yaml > openapi.public.yaml

Result in:

paths:
  /timeseries:
    get:
      operationId: searchTimeSeriesDefinitions
      summary: Search the time series definitions
      description: Retrieve a list of all time series definitions. This endpoint supports search and pagination.
      parameters:
        - name: searchPattern
          in: query
          description: Pattern to search time series definitions. Cannot be used at the same time as name parameter.
          required: false
          schema:
            type: string
        - name: searchPattern
          in: query
          description: A pattern used to search time series definitions.
          schema:
            example: temp*

Expected result

paths:
  /timeseries:
    get:
      operationId: searchTimeSeriesDefinitions
      summary: Search the time series definitions
      description: Retrieve a list of all time series definitions. This endpoint supports search and pagination.
      parameters:
        - name: searchPattern
          in: query
          description: A pattern used to search time series definitions.
          required: false
          schema:
            type: string
            example: temp-
@thim81
Copy link
Author

thim81 commented Sep 12, 2024

I think, it would make sense to provide an explicit merge instruction for the "parameters".

This will handle that the parameters are merged intelligently by checking for existing parameters with the same name and path location (in: query in this case)

Something like this?

jsonpath.apply(spec, target, (chunk) => {
  if (typeof chunk === 'object' && typeof action.update === 'object') {
    if (Array.isArray(chunk) && Array.isArray(action.update)) {
      // Handle array merging carefully to avoid duplicating parameters
      if (target.includes('parameters')) {
        // Merge the parameters array by checking if parameter already exists
        const mergedParameters = [...chunk];
        action.update.forEach((newParam: any) => {
          const existingParamIndex = mergedParameters.findIndex(
            (p: any) => p.name === newParam.name && p.in === newParam.in
          );
          if (existingParamIndex > -1) {
            // Update the existing parameter
            mergedParameters[existingParamIndex] = merger(mergedParameters[existingParamIndex], newParam);
          } else {
            // Add the new parameter if it doesn't exist
            mergedParameters.push(newParam);
          }
        });
        return mergedParameters;
      } else {
        // For arrays that are not parameters, just concatenate
        return chunk.concat(action.update);
      }
    } else {
      return merger(chunk, action.update);
    }
  } else {
    return action.update;
  }
});

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

1 participant