Comments (23)
I see. We could give you operation ID transformers, hang on!
from openapi-ts.
Have you tried it @anchan828? If it fulfils all your requirements, feel free to close the issue ๐ค
from openapi-ts.
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.
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.
Start a new pull request in StackBlitz Codeflow.
from openapi-ts.
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.
@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.
@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.
What would be a good solution for you @syabro?
from openapi-ts.
@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.
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.
...
"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.
Ew. Yeah we will have to improve this ๐งน
from openapi-ts.
@mrlubos should I try to check and make a PR?
from openapi-ts.
Hi, This issue can be resolved by this PR. Should I leave this issue open?
#663
from openapi-ts.
@syabro Can you check if there's anything missing for your use case?
from openapi-ts.
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.
@mrlubos will check a bit later, thanks!
from openapi-ts.
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.
@Stono check out this thread
from openapi-ts.
Seems legit to me ๐
from openapi-ts.
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.
Appreciate the consideration though :)
from openapi-ts.
Related Issues (20)
- Using wrong client config parameter leads to undefined HttpRequestConstructor HOT 3
- BaseURL not being set when using client.setConfig HOT 1
- Tanstack Query Incorrect onError Types HOT 4
- Improved types for Vue Tanstack Query HOT 1
- Concurrent createClient calls resolve to same input HOT 1
- fetch-api mistakenly serializes FormData as application/json instead of multipart/form-data
- Parameter in path with multiple dollar sign gets replaced to a single dollar sign HOT 3
- Improper handling of array query types HOT 6
- Having trouble setting up client with next js and fetch api HOT 3
- Properties are declared `?` when they're not in the openapi spec HOT 3
- Type of error object changed HOT 2
- Cannot specify responseTransformer when request options include headers HOT 1
- Generating code based on multiple OpenAPI schemas HOT 2
- Automatic addition of the suffix `Schema` to the object names in `schemas.gen.ts` causes conflicts with `types.gen.ts` HOT 3
- Intergrate with `msw` mock service HOT 1
- Improve changelog
- Test bundle-require
- Angular client
- Posibility to add no client HOT 9
- Big int for Format int64 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi-ts.