Giter Site home page Giter Site logo

Comments (23)

mrlubos avatar mrlubos commented on September 22, 2024 1

I see. We could give you operation ID transformers, hang on!

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024 1

Have you tried it @anchan828? If it fulfils all your requirements, feel free to close the issue ๐Ÿค

from openapi-ts.

Stono avatar Stono commented on September 22, 2024 1

Happy to do the migration. The more options you give to the user in a method designed to give them control makes sense.

from openapi-ts.

anchan828 avatar anchan828 commented on September 22, 2024 1

I created has been resolved issue now that the PR has been merged. If anyone is still experiencing issues, I think you can create a new one. Thank you, everyone!
#696

from openapi-ts.

stackblitz avatar stackblitz commented on September 22, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024

I see why you'd want to do this @anchan828, I thought about it before. However, please be aware of the upcoming clients feature. Part of that release will be flattening the services layer so every method will be exported as a separate function. This will make it possible to do tree shaking on the final bundle. Unfortunately, this also means that your function names will have to be truly unique, just like operation IDs. Would you still need to transform operation ID in that case?

from openapi-ts.

anchan828 avatar anchan828 commented on September 22, 2024

@mrlubos Thanks for the details. I understand how it will be updated in the future.
Depending on the unique function name, I might want to swap the tag name and order.

Tag_get -> client.tagGet
Tag_get -> transform operationId -> client.getTag

To maintain backward compatibility, conversion will be necessary in one of the tools, as operationId is used in various places like Swagger UI URLs. Especially for released document URLs, if the issue is specific to operationId in openapi_ts, I would prefer to handle the conversion there to avoid changing the URLs if possible.

If I use openapi_ts in a new product in the future, I will use getTag for operationId from the beginning, so the conversion will not be necessary.

from openapi-ts.

syabro avatar syabro commented on September 22, 2024

@mrlubos I want this as well. Duplication sucks :(

export class CategoriesApi {
    public static categoriesApiList(): CancelablePromise<CategoriesApiListResponse> {
        /// ...
    }
    
    public static categoriesApiGet(data: CategoriesApiGetData): CancelablePromise<CategoriesApiGetResponse> {
        ///...
    }
    
}

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024

What would be a good solution for you @syabro?

from openapi-ts.

syabro avatar syabro commented on September 22, 2024

@mrlubos ideally in config something like

service: {
   methodNameGenarator: (operationId, serviceClassName) => {
       const newMethodName = operationId.replace(serviceClassName, '');
       return newMethodName.charAt(0).toLowerCase() + newMethodName.slice(1) 
  }
}

For the record I added npx fix_names.ts after the generation but I think it's fragile...

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024

Are you executing openapi-ts programmatically through Node.js? That would be the way to add support for executable function as you described it... can you share what's your fix_names script?

from openapi-ts.

syabro avatar syabro commented on September 22, 2024
...
"generate-openapi": "pnpm openapi-ts; pnpm tsx ./src/openapi/fix_names.ts",
...
import * as fs from 'fs'
import * as path from 'path'
import { fileURLToPath } from 'url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

function removeClassNameFromMethods(filePath: string) {
  const content = fs.readFileSync(filePath, 'utf-8')

  const classNameMatch = content.match(/class\s+(\w+)\s*{/)

  let updatedContent = content
  for (const match of content.matchAll(/class\s+(\w+)\s*{/g)) {
    const className = match[1]
    const prefix = className.charAt(0).toLowerCase() + className.slice(1)
    const pattern = new RegExp(`(public\\s+static\\s+)${prefix}(\\w+)(\\s*\\()`, 'g')

    updatedContent = updatedContent.replace(pattern, (fullMatch, p1, p2, p3) => {
      const newMethodName = p2.charAt(0).toLowerCase() + p2.slice(1)
      return `${p1}${newMethodName}${p3}`
    })
    console.log(`Removing class name from methods in class ${className}`)
  }

  fs.writeFileSync(filePath, updatedContent, 'utf-8')
}

const filePath = path.join(__dirname, 'services.gen.ts')
removeClassNameFromMethods(filePath)

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024

Ew. Yeah we will have to improve this ๐Ÿงน

from openapi-ts.

syabro avatar syabro commented on September 22, 2024

@mrlubos should I try to check and make a PR?

from openapi-ts.

anchan828 avatar anchan828 commented on September 22, 2024

Hi, This issue can be resolved by this PR. Should I leave this issue open?
#663

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024

@syabro Can you check if there's anything missing for your use case?

from openapi-ts.

anchan828 avatar anchan828 commented on September 22, 2024

In practice, the operationId passed in the methodNameGenarator is not the actual value, but rather the camel-cased version of it, so I will create an issue as soon as I create a reproduction project, but I think the approach itself is very good. My issue idea will affect everything, and there seems to be a conflict with ParamType.

If there are no comments from anyone in particular, I will close it after waiting a few days.

from openapi-ts.

syabro avatar syabro commented on September 22, 2024

@mrlubos will check a bit later, thanks!

from openapi-ts.

anchan828 avatar anchan828 commented on September 22, 2024

I will create an issue as soon as I create a reproduction project

Created issue and PR.
#695
#696

I've created the PR, but I don't mind at all if it's not merged because I want to hear your opinions.๐Ÿ˜€

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024

@Stono check out this thread

from openapi-ts.

Stono avatar Stono commented on September 22, 2024

Seems legit to me ๐Ÿ‘

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024

Let's provide the whole operation to the user, they can pick whichever properties they like. Should be a straightforward migration for you, but let me know if you disagree

from openapi-ts.

Stono avatar Stono commented on September 22, 2024

Appreciate the consideration though :)

from openapi-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.