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

Support the use of string or number via $ref in path parameters #225

Merged
merged 1 commit into from
Aug 4, 2023

Conversation

hadashiA
Copy link
Contributor

@hadashiA hadashiA commented Dec 21, 2022

Types of changes

  • Bug fixes
    • resolves #
  • Features
    • resolves #
  • Maintenance
  • Documentation

Changes

  • Support the use of custom types in path parameters if type is actually alias of string or number.

Additional context

Currently, only number or string can be used for the path parameters.

( This is validation on the side of aspida/aspida. https://github.com/aspida/aspida/blob/main/packages/aspida/src/createTemplateValues.ts#L9 )

In openapi2aspida, even if it is a string or a number, an error will occur if a $ref reference is interposed.

In my use case, I want to define the path parameter string as follows:

paths:
  "/invoices/{invoiceCategory}":
    get:
      parameters:
      - name: invoiceCategory
        in: path
        required: true
        schema:
          "$ref": "#/components/schemas/InvoiceCategory"
components:
  schemas:
    InvoiceCategory:
      type: string
      enum: ["category-1", "category-2"]

openapi2aspida does not know that "$ref": "#/components/schemas/InvoiceCategory" is actually a string.

└── invoices/
    └── [email protected]

Therefore,

Error: aspida ERROR '[email protected]' does not match '/^_[a-zA-Z][a-zA-Z0-9_]*(@number|@string)?((\.|%[0-9a-fA-F]{2})[a-zA-Z0-9]+)?$/'.
    at /Users/hadashi/src/github.com/aspida/openapi2aspida/node_modules/aspida/dist/createTemplateValues.js:42:27
    at Array.map (<anonymous>)
    at createApiString 
...

So, in this PR, I added a process to check the destination of $ref and fallback if it is a simple string type.

Community note

Please upvote with reacting as 👍 to express your agreement.

@hadashiA hadashiA force-pushed the ku/support-enum-path-params branch from 67e957a to ad500b5 Compare December 21, 2022 09:25
@hadashiA hadashiA changed the title Allow enum to be used for path parameters Support the use of custom types in path parameters if type is actually alias of string or number Dec 28, 2022
@hadashiA hadashiA changed the title Support the use of custom types in path parameters if type is actually alias of string or number Support the use of string or number via $ref Dec 28, 2022
@hadashiA hadashiA changed the title Support the use of string or number via $ref Support the use of string or number via $ref in path parameters Dec 28, 2022
@solufa solufa merged commit d729e4d into aspida:main Aug 4, 2023
@hadashiA hadashiA deleted the ku/support-enum-path-params branch October 3, 2023 07:06
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