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

Nested custom object having oneOf in swagger file result in empty model after code generation #4921

Open
dev49010 opened this issue Mar 15, 2024 · 3 comments
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@dev49010
Copy link

I am in the following situation:

I have a class in C# language defining primitive types + 1 custom type.

public class User {
public string firstName { get; set; }
public string lastName { get; set; }
public CustomCredentials customCredentials { get; set; }
}

public class CustomCredentials {
public string password { get; set; }
}

User class appears in my .NetCore controller in the endpoint where it is used, as part of
[SwaggerResponse(200. typeof(User))]

The corresponding part for CustomCredentials into swagger.json file is

"customCredentials": {
"nullable:" true,
"oneOf": [
"$ref": "#components/schemas/customCredentials"
]
}

During code generation a warning appears reporting The schema for that class with an undefined type and 'allOf/anyOf/oneOf is a bit ambiguous. As side effect the generated typescript class for customCredentials is empty, while the parent class is ok.

As workaround if I manually replace oneOf with allOf in swagger file before the library generation then the model is populated correctly.

Is there a right way to approach this problem?

Thanks

@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 15, 2024
@dev49010
Copy link
Author

dev49010 commented Mar 16, 2024

I am looking for the directive syntax to transform oneOf property into allOf property since it represents a solution.
I am able to write and use directives to reassign values but I haven't found the correct syntax to rename properties.

@lirenhe
Copy link

lirenhe commented Mar 20, 2024

seems the ask is about the directive authoring, move it to autorest repo.

@lirenhe lirenhe transferred this issue from Azure/autorest.typescript Mar 20, 2024
@timotheeguerin
Copy link
Member

Autorest does not support oneOf or anyOf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

3 participants