Comments (11)
Before I noticed the flag, I asked about the purpose in kean/Get#33 and you are right, it is designed for this.
So in that case, maybe we do just pass the id
through the convenience methods.. something like this:
public static func get(_ url: String, query: [(String, String?)]? = nil, headers: [String: String]? = nil, id: String? = nil) -> Request {
Request(method: "GET", url: url, query: query, headers: headers, id: id)
}
What do you think about this @kean?
from createapi.
Yes, I recommend using the initializer because otherwise, you might end up using methods that'll get deprecated soon. The initializer won't change any time soon or ever.
from createapi.
Just taking a look at this, should we just always generate a functional helper:
public extension Request {
public func settingID(_ id: String) -> Request { // different name, but functional in context
var copy = self
copy.id = id
return copy
}
}
from createapi.
Could it even just be a case of removing the private
from the existing template?
from createapi.
Ultimately yes, but this seems so small to be behind a flag especially since the user can just edit the id
variable directly. Additionally, the functional name could be a change.
from createapi.
Or, this could be a change in Get itself as it seems more appropriate there
from createapi.
Using isAddingOperationIds
will fail if the schema doesn't specify an operationId
for one or more of its operations, which is allowed as per the spec.
So at the moment, the flag is necessary. But that being said, I've seen other tools automatically infer the operationId from the path + method, which we could also do. And if we did, then we'd be able to just generate it automatically (or maybe just leave it as nil
?)
Or, this could be a change in Get itself as it seems more appropriate there
Yeah I did think about that and it is also a possibility. It would simplify things
from createapi.
I think it would be safe to add the operationId
as the Request.id
by default, nil
if none specified. Get does not use the id
property so it's mainly for developer usage (unless I'm missing something or it has actual Request usage in somebody's package).
from createapi.
I'm still debating how to design it. I don't think I've done a great job with all these telescoping methods. There are too long, duplicated, and I keep forgetting the order of parameters.
I'm thinking about taking a cue from the SwiftUI design:
// Now
_ = Request.post(
"/domain.tld",
query: [("query", "value1+value2")],
body: value,
headers: ["a": "b"]
).withId("getDomains")
// Target state
_ = Request.post("/domain.tld", body: value)
.query([("query", "value1+value2")])
.headers(["a": "b"])
.id("getDomains")
But I'm not sure it'll work well with the existing writable properties with the same names. It does work, but I'm sure there are going to be some issues because of the name clashes.
from createapi.
Right now you can use the existing initializer for code generation purposes:
public init(
method: String = "GET",
url: String,
query: [(String, String?)]? = nil,
body: Encodable? = nil,
headers: [String: String]? = nil,
id: String? = nil
) {
It didn't have the id
parameter prior to Get 1.0, but it does now.
from createapi.
Thanks for the input! Ok that makes sense, the telescoping methods (TIL) methods are more for manual usage and it doesn't really matter what the generated code uses. We can generate implementations that use Request.init(...)
directly instead 👍
from createapi.
Related Issues (20)
- Schema component named `Request` generates ambiguous code HOT 4
- `AnyJSON` type included unexpectedly
- Adjust behaviour of `includeDefaultValues` to favour "correctness" by default HOT 1
- integer backed enums are stored as integer properties as opposed to enums HOT 1
- generated package depends on an old version of Get HOT 3
- Tagged type for IDs? HOT 2
- FR: Entity replace substring, instead of naming template HOT 1
- Equatable conformance HOT 1
- Parameters to be passed in headers are ignored during API generation
- Acronyms change property names without changing corresponding CodingKeys
- Deduplicate identical structs/classes
- Add option to separate GET from POST and PATCH requests and only include Decodable respectively Encodable conformance
- Option for treating non-optional enum with only one case as a static value
- `type` definition in OpenAPI spec is overridden by `format` value
- Is there a way to generate `CodingKeys`?
- How to wildcard rules in include and exclude paths
- Use `Swift Syntax`
- Make 'Request' type name configurable HOT 1
- Will OpenAPI schema v3.1.0 be supported?
- Documentation on how to use decoded entity fields 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 createapi.