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

code generation for TypeScript about JsonExtensionData #1541

Open
elementuse opened this issue Aug 16, 2018 · 8 comments
Open

code generation for TypeScript about JsonExtensionData #1541

elementuse opened this issue Aug 16, 2018 · 8 comments

Comments

@elementuse
Copy link

Is JsonExtensionData code generation not supported in typescript?

@RicoSuter
Copy link
Owner

@elementuse
Copy link
Author

in typescript.
is this code generator support?

@RicoSuter
Copy link
Owner

Yes, but you need something like this in typescript?

@elementuse
Copy link
Author

yes. using typescript, my data was filtered out by the proxy class.

@RicoSuter
Copy link
Owner

Yep, not implemented yet...

@elementuse
Copy link
Author

How to avoid this problem and let my data display?
is there any good way?

@RicoSuter
Copy link
Owner

I think the only way to fix that right now is to use interfaces instead of classes for DTOs...

@Sharparam
Copy link

What's the status on this?

Not sure if it belongs here or in a new issue, but the code in the generated TypeScript code to handle JsonExtensionData doesn't seem to follow spec. It expects there to be a property "extensions" in the JSON data but that will not be there in correctly generated JSON, as specified in the documentation for the property Extensions on ProblemDetails:

Extension members appear in the same namespace as other members of a problem type.

So for example, given this constructed ProblemDetails:

new ProblemDetails
{
	// ...
	Extensions =
	{
		["CustomExtension"] = "custom value"
	}
};

The following JSON will be generated (standard fields omitted):

{
	"CustomExtension": "custom value"
}

However, NSwag's TypeScript code expects this:

{
	"extensions": {
		"CustomExtension": "custom value"
	}
}

Not sure how the C# JSON libraries handle them, but I suppose the way to handle it is to treat any root-level field on the JSON that doesn't have a matching property in the TypeScript class/interface as an extension and stuff it into the "extensions" property on the TypeScript class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants