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

oas2tson return path parameters as array instead of objects #293

Open
princeede opened this issue Jul 25, 2024 · 1 comment
Open

oas2tson return path parameters as array instead of objects #293

princeede opened this issue Jul 25, 2024 · 1 comment

Comments

@princeede
Copy link

Using this toolkit to generate TS JSON schemas returns the path parameters as an array instead of objects for each path.

For example, the yaml file below

...
paths:
  /pet/findByStatus:
    get:
      tags:
        - pet
      summary: Finds Pets by status
      description: Multiple status values can be provided with comma separated strings
      operationId: findPetsByStatus
      parameters:
        - name: status
          in: query
          description: Status values that need to be considered for filter
          required: false
          explode: true
          schema:
            type: string
            default: available
            enum:
              - available
              - pending
              - sold
...

will generate the output

export const PetFindByStatus = {
  get: {
    tags: ["pet"],
    summary: "Finds Pets by status",
    description:
      "Multiple status values can be provided with comma separated strings",
    operationId: "findPetsByStatus",
    parameters: [
      {
        name: "status",
        in: "query",
        description: "Status values that need to be considered for filter",
        required: false,
        explode: true,
        schema: {
          type: "string",
          default: "available",
          enum: ["available", "pending", "sold"],
        },
      },
    ],
    ...
} as const;

This means the output cannot be used directly in fastify schemas without writing some scripts to extract headers/path/query/cookies based on the open API standard describing parameters

Instead of an array, parameters should return an object in the format

...
 parameters: {
      headers: {...},
      path: {...},
      query: {...},
      cookies: {...}

        required: [...],
        type: 'object'
      }
    }
...
@jmjf
Copy link
Contributor

jmjf commented Nov 8, 2024

I think this is related to issues discussed in #305 and #318.

FWIW, my solution to this is to write query, header, etc., parameters in schemas then $ref the schemas in paths and pass them to query, etc., in Fastify. For example:

components:
   schemas:
      ExampleQuery:
         description: I can provide a detailed description that shows up in Redocly-generated docs.
         type: object
         required:
            - param1
         properties:
            param1:
               # parameter details
            param2:
               # parameter details
   parameters:
      ExampleQueryParameter:
         name: exampleQuery
         in: query
         schema:
            $ref: '#/components/schemas/ExampleQuery'
      ExampleHeaderParameter:
         in: header
         # etc.
paths:
   get:
      parameters:
         - $ref: '#components/parameters/ExampleQueryParameter
         - $ref: '#/components/parameters/ExampleHeaderParameter
      # etc.
// in Fastify schema
parameters: {
    query: ExampleQuery,
    headers: ExampleHeader,
    // etc.
}

I haven't used this approach with cookies, but it works for header, path, and query parameters.

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

2 participants