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

Fix how path variables are escaped for Swagger #5246

Merged
merged 18 commits into from
Oct 24, 2022

Conversation

AntoineJac
Copy link
Contributor

@AntoineJac AntoineJac commented Oct 4, 2022

changelog(Fixes): Fixed an issue where Path variables weren't properly escaped for Swagger specs

paths in swagger are not correctly escaped and won't be correct. You can try with following swagger:

openapi: 3.0.0
info:
 title: SampleAPI
 version: "1.0"
tags:
  - description: Sample API
    name: Sample Echo API
paths:
  /healthcheck/$echo:
    get:
      parameters:
        - in: query
          name: message
          required: true
          schema:
            type: string
          description: The echo message
      responses:
        "200":
          description: An echo message.
      summary: Return a echo message.
      operationId: getEcho
      tags:
        - Generate echo message
  /batchs(Material='{Material}',Batch='{Batch}'):
    get:
      parameters:
        - in: path
          name: Material
          required: true
          schema:
            type: string
          description: The echo message
        - in: path
          name: Batch
          required: true
          schema:
            type: string
          description: The echo message
      responses:
        "200":
          description: An echo message.
      summary: Return a echo message.
      operationId: getBatch
      tags:
        - Generate echo message
servers:
  - url: https://httpbin.org/anything`

@marckong
Copy link
Contributor

marckong commented Oct 4, 2022

According to the internal slack thread, the translation of the following string should be,

Source:

/Batchs(Material=''{Material}'',Batch=''{Batch}''):

Expected:,

"/Batchs\(Material='(?<Material>[^\/]+)',Batch='(?<Batch>[^\/]+)'\)$"

Actual:,

"/Batchs\\(Material=''(?<Material>[^\\/]+)'',Batch=''(?<Batch>[^\\/]+)''\\)$"

@AntoineJac
Copy link
Contributor Author

@marckong this was an issue with the UI, I fixed it. Can you please review? Thanks

@filfreire filfreire changed the title Patch 1 Fix how path variables are escaped for Swagger Oct 11, 2022
@AntoineJac
Copy link
Contributor Author

Source:
/Batchs(Material=''{Material}'',Batch=''{Batch}''):

Expected:,
"/Batchs\(Material='(?<Material>[^/]+)',Batch='(?<Batch>[^/]+)'\)$"

Actual:,
"/Batchs\(Material='(?<Material>[^/]+)',Batch='(?<Batch>[^/]+)'\)$"

paths in swagger are not correctly escaped and won't be correct. You can try with following swagger:

openapi: 3.0.0
info:
 title: SampleAPI
 version: "1.0"
tags:
  - description: Sample API
    name: Sample Echo API
paths:
  /healthcheck/$echo:
    get:
      parameters:
        - in: query
          name: message
          required: true
          schema:
            type: string
          description: The echo message
      responses:
        "200":
          description: An echo message.
      summary: Return a echo message.
      operationId: getEcho
      tags:
        - Generate echo message
  /batchs(Material='{Material}',Batch='{Batch}'):
    get:
      parameters:
        - in: path
          name: Material
          required: true
          schema:
            type: string
          description: The echo message
        - in: path
          name: Batch
          required: true
          schema:
            type: string
          description: The echo message
      responses:
        "200":
          description: An echo message.
      summary: Return a echo message.
      operationId: getBatch
      tags:
        - Generate echo message
servers:
  - url: https://httpbin.org/anything
@marckong
Copy link
Contributor

I ran smoke test to spin up a Kong gateway and it seems to be fine.

image

@marckong
Copy link
Contributor

Ran smoke tests with the link example as well

image

Copy link
Contributor

@marckong marckong left a comment

Choose a reason for hiding this comment

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

This change is minimal. I tested out all the examples except those that don't meet openapi spec requirements, which failed to generate deck (happen in the develop branch too)

@marckong marckong merged commit d102de2 into Kong:develop Oct 24, 2022
Tieske added a commit to Kong/fw that referenced this pull request Feb 12, 2023
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.

2 participants