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

Generating examples for abstract request type #236

Open
michaeljon opened this issue Oct 24, 2023 · 4 comments
Open

Generating examples for abstract request type #236

michaeljon opened this issue Oct 24, 2023 · 4 comments

Comments

@michaeljon
Copy link

I have a controller that take an abstract base class as the input. I'm using JsonDerivedType to tell System.Text.Json how to turn the inbound data into a concrete type. I'd like to provide examples for the various types but am running into an issue where the IMultipleExamplesProvider has to take the abstract type and then when the example is serialized the type information is lost from the more concrete type. This loses the $type discriminator in the examples. I really don't want to write these as XML examples - the magic strings are going to get way out of date.

Is there something I'm missing? I've tried type-specific examples but can only use on SwaggerRequestExample per method and the last one wins.

@mattfrear
Copy link
Owner

Hello

I've never used IMultipleExamplesProvider myself. According to my changelog, they were contributed by @tomkludy and @pozy.

Sorry for the delay in responding - I thought I would have time to have a play myself and see if I could figure it out, but I haven't had a chance to play yet, and I can't make any promises.

@pozy
Copy link

pozy commented Nov 10, 2023

Hi,
Can you provide your implementation of IMultipleExamplesProvider which you have problem with? And screenshot how it looks in Swagger?
I don't remember much of this code, but will try to check what's going on.

@svha1977
Copy link

svha1977 commented Apr 17, 2024

@pozy @mattfrear
I have the same issue.

Look at the schema - it has the discriminator in the schema
image

But the example leave it out.
image

It seems its related to the oneOf is at the root of the actual request like
image

If the oneOf is nested with another object it does it correctly.
image

Examples basically just returning the types of OneOf like

image

@mattfrear
Copy link
Owner

I closed this issue because of the lack of reply from OP.
Like I said earlier, I've never used IMultipleExamplesProvider myself, so I'm not gonna be able to help here.

I'm not convinced that @svha1977's issue is the same issue which OP has. I'm not gonna be able to fix either issue, so someone else will have to provide a PR.

@mattfrear mattfrear reopened this Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants