Skip to content

Add support for declaring path parameters on path item object instead of operation object #173

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

Merged
merged 7 commits into from
Feb 24, 2022

Conversation

danielmbaluka
Copy link
Contributor

@danielmbaluka danielmbaluka commented Feb 7, 2022

Fixes #159

This PR add support for declaring path parameters on the path item object instead of the operation object. This feature is controlled by a new flag (DeclarePathParametersOnPathItem) on OpenApiConvertSettings

Example usage:

    OpenApiConvertSettings settings = new()
    {
        DeclarePathParametersOnPathItem = true,
    };
    ODataContext context = new ODataContext(model, settings);

Example output

  '/Airports/{IcaoCode}':
    description: Provides operations to manage the collection of Airport entities.
    get:
      tags:
        - Airports.Airport
      summary: Get entity from Airports by key
      operationId: Airports.Airport.GetAirport
      parameters:
-       - name: IcaoCode
-         in: path
-         description: 'key: IcaoCode of Airport'
-         required: true
-         schema:
-           type: string
-         x-ms-docs-key-type: Airport
        - name: $select
          in: query
          description: Select properties to be returned
          style: form
          explode: false
          schema:
            uniqueItems: true
            type: array
            items:
              enum:
                - Name
                - IcaoCode
                - IataCode
                - Location
              type: string
        - name: $expand
          in: query
          description: Expand related entities
          style: form
          explode: false
          schema:
            uniqueItems: true
            type: array
            items:
              enum:
                - '*'
              type: string
      responses:
        '200':
          description: Retrieved entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport'
        default:
          $ref: '#/components/responses/error'
      x-ms-docs-operation-type: operation
    patch:
      tags:
        - Airports.Airport
      summary: Update entity in Airports
      operationId: Airports.Airport.UpdateAirport
      parameters:
-       - name: IcaoCode
-         in: path
-         description: 'key: IcaoCode of Airport'
-         required: true
-         schema:
-           type: string
-         x-ms-docs-key-type: Airport
      requestBody:
        description: New property values
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport'
        required: true
      responses:
        '204':
          description: Success
        default:
          $ref: '#/components/responses/error'
      x-ms-docs-operation-type: operation
    delete:
      tags:
        - Airports.Airport
      summary: Delete entity from Airports
      operationId: Airports.Airport.DeleteAirport
      parameters:
-       - name: IcaoCode
-         in: path
-         description: 'key: IcaoCode of Airport'
-         required: true
-         schema:
-           type: string
-         x-ms-docs-key-type: Airport
        - name: If-Match
          in: header
          description: ETag
          schema:
            type: string
      responses:
        '204':
          description: Success
        default:
          $ref: '#/components/responses/error'
      x-ms-docs-operation-type: operation
+   parameters:
+   - name: IcaoCode
+      in: path
+      description: 'key: IcaoCode of Airport'
+      required: true
+      schema:
+        type: string
+      x-ms-docs-key-type: Airport

@danielmbaluka danielmbaluka force-pushed the feature/dm/add-path-parameters-to-path-item branch 2 times, most recently from 12ff812 to 033703d Compare February 7, 2022 09:06
@danielmbaluka danielmbaluka changed the title create path parameters in path item Add support for declaring path parameters on path item object instead of operation object Feb 7, 2022
@danielmbaluka danielmbaluka marked this pull request as ready for review February 7, 2022 09:31
@danielmbaluka danielmbaluka requested a review from baywet February 7, 2022 09:32
@baywet baywet added this to the 1.0.10 milestone Feb 7, 2022
Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking that, a few comments.

@irvinesunday
Copy link
Contributor

Let's keep in mind that OpenApiLinks are currently generated based on the operation parameters:

image

We still need to be able to generate these links even when the parameters are not available at the operation level.

@darrelmiller darrelmiller removed this from the 1.0.10 milestone Feb 10, 2022
@danielmbaluka
Copy link
Contributor Author

Let's keep in mind that OpenApiLinks are currently generated based on the operation parameters:

image

We still need to be able to generate these links even when the parameters are not available at the operation level.

Thanks @irvinesunday for catching this (and the suggestion on how to handle it). I have pushed a fix for to resolve it c136516

@danielmbaluka
Copy link
Contributor Author

@baywet @irvinesunday @xuzhg @darrelmiller kindly have a look at the PR.

@danielmbaluka danielmbaluka force-pushed the feature/dm/add-path-parameters-to-path-item branch from c136516 to b171a2d Compare February 23, 2022 06:21
@baywet baywet merged commit 34d13b2 into master Feb 24, 2022
@baywet baywet deleted the feature/dm/add-path-parameters-to-path-item branch February 24, 2022 17:45
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

Successfully merging this pull request may close these issues.

Path parameters should be declared on the Path Item object and not on the Operation object
4 participants