-
Notifications
You must be signed in to change notification settings - Fork 230
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
Adding models + interfaces #675
base: dev
Are you sure you want to change the base?
Adding models + interfaces #675
Conversation
- [NodeJS e2e using the Service library](#node-service-library) | ||
- [NodeJS e2e using the Core library](#node-core-library) | ||
|
||
## <a id="foundation"></a> Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## <a id="foundation"></a> Foundation | |
## Foundation |
github adds the anchors automatically for you when using headings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They don't allow me to "know" what will be the generated anchor. So I prefer this for more complex TOCs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it uses kebab casing Foundation => foundation, My Foundation => my-foundation
```typescript | ||
export class SendMailRequestBody implements Parsable, SendMailRequestBody { | ||
/** Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. */ | ||
private _additionalData: Map<string, unknown>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update additionalData to Record @nikithauc is already working on that change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just there are an "example". Didn't mean to replicate the actual implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then add a comment saying the purpose of this snippet is to demonstrate the api surface, not the implementation details. I don't want people to mistake that for a technical spec
Thanks to the TypeScript nature of allowing merging of Classes and Interfaces with the same name, models are represented in a way that allows both rich capabilities of the classes (backing stores, dirty tracking, etc.) and simplicity of using interfaces. | ||
|
||
```typescript | ||
export class SendMailRequestBody implements Parsable, SendMailRequestBody { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a comment mentioning that interfaces and classes might have a different name or live in different packages depending on implementation/runtime constraints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup
*/ | ||
public constructor(value?: Partial<SendMailRequestBody>) { | ||
if(value) { | ||
Object.assign(this, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this section might be a bit more complex than that, we need to account for properties that are complex types (message body) or collections of complex types (message to recipients) as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the goal. I Think I'll simply remove the code. This is not meant for the internal implementation, but the way developers use the SDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, replace by a comment saying the actual implementation object gets instantiated from the partial values
This PR should be in somewhere Kiota because this is the design applicable to the generation process. |
|
||
The models should be easily consumable by developers in a natural format. For JavaScript and TypeScript developers, interfaces are the most common way to understand, represent and send data to endpoints. | ||
|
||
Thanks to the TypeScript nature of allowing merging of Classes and Interfaces with the same name, models are represented in a way that allows both rich capabilities of the classes (backing stores, dirty tracking, etc.) and simplicity of using interfaces. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing a class and interface with the same name gives me this issue.
Try the following:
//File a.ts
export interface name{
id:string;
test:string;
}
export class name{
id:string;
type:string;
test:string;
public getFieldDeserializers():Array<string>{
return ["name","type"];
}
}
//b.ts
import {name} from "./a";
const test: name ={ id:"name", type:"type"};
I get a prompt on the test
variable that Error: Type '{ id: string; type: string; }' is missing the following properties from type 'name': test, getFieldDeserializersts(2739).
Interfaces can have duplicate names and that works fine in TypeScript because they do not transpile. However, we are not getting rid of the problem that we see today that requires all properties to be set when using a json initialization pattern because the class requires all the properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need to think about the import pattern when using same named interfaces and classes.
No description provided.