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

Ability to generate enum for endpoint urls #1120

Open
aaronb-reach opened this issue Aug 12, 2024 · 1 comment
Open

Ability to generate enum for endpoint urls #1120

aaronb-reach opened this issue Aug 12, 2024 · 1 comment
Labels
enhancement New feature or request @kubb/plugin-ts
Milestone

Comments

@aaronb-reach
Copy link

aaronb-reach commented Aug 12, 2024

What is the problem this feature would solve?

This is to solve not having to duplicate endpoint urls in code. It would be neat if the kubb generation could do this for us in some way when using @kubb/swagger-ts. I dont know whats possible but something like:

Example openapi spec:

openapi: '3.0.2'
info:
  title: Example API
  version: '1.0'
servers:
  - url: https://example.com/v2
paths:
  /object/create:
    post:
      summary: Create an object
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ObjectRequest'
      responses:
        '200':
          description: Object created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ObjectResponse'

Generated output:

export const videoStreamStatusEnum = {
    "v2ObjectCreate": "/v2/object/create",
} as const;

What do you think? Is something like this already possible?

Cheers!

External documents/projects?

No response

What is the feature you are proposing to solve the problem?

No response

What alternatives have you considered?

No response

@aaronb-reach aaronb-reach added the enhancement New feature or request label Aug 12, 2024
@stijnvanhulle stijnvanhulle added this to the 3.0.0 milestone Sep 22, 2024
@stijnvanhulle
Copy link
Collaborator

@aaronb-reach If you are using the Client Plugin, then a operations.ts file will be created containing all your api endpoints.

Example src/gen/operations.ts:

export const operations = {
  updatePet: {
    path: '/pet',
    method: 'put',
  },
  addPet: {
    path: '/pet',
    method: 'post',
  },
  findPetsByStatus: {
    path: '/pet/findByStatus',
    method: 'get',
  },
  findPetsByTags: {
    path: '/pet/findByTags',
    method: 'get',
  },
  getPetById: {
    path: '/pet/:petId',
    method: 'get',
  },
  updatePetWithForm: {
    path: '/pet/:petId',
    method: 'post',
  },
  deletePet: {
    path: '/pet/:petId',
    method: 'delete',
  },
  uploadFile: {
    path: '/pet/:petId/uploadImage',
    method: 'post',
  },
  createUser: {
    path: '/user',
    method: 'post',
  },
  createUsersWithListInput: {
    path: '/user/createWithList',
    method: 'post',
  },
  loginUser: {
    path: '/user/login',
    method: 'get',
  },
  logoutUser: {
    path: '/user/logout',
    method: 'get',
  },
  getUserByName: {
    path: '/user/:username',
    method: 'get',
  },
  updateUser: {
    path: '/user/:username',
    method: 'put',
  },
  deleteUser: {
    path: '/user/:username',
    method: 'delete',
  },
} as const

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request @kubb/plugin-ts
Projects
None yet
Development

No branches or pull requests

2 participants