-
-
Notifications
You must be signed in to change notification settings - Fork 514
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
The schema defined in the content of RequestBody ignores the setting of discriminator #356
Comments
Can you please add more details about your request :
Thank you in advance. |
I am using the following annotation in the code @operation( The expect result is "requestBody": { But the actual result is "requestBody": { While I debug into the code, the requestbody is constructed in org.springdoc.core.RequestBodyBuilder and the Schema of the Content is extracted from method getSchemaFromAnnotation in class io.swagger.v3.core.util.AnnotationsUtils |
Hi @lawli, As you have described, this behaviour is mainly related to swagger-api. You can look at the sample how to generate the discriminator in the documentation. The following issue, contains an example of how to get the discriminator in the documentation: |
I don't think it is the problem of swagger-api. If I populate the ComposedSchema manually, it shows the expected result. public OpenApiCustomiser apiCustomerser() { return openApi -> { MediaType md = new MediaType(); Discriminator ds = new Discriminator(); ds.setPropertyName("transactionType"); ds.mapping("DEBIT", "#/components/schemas/Debit"); ds.mapping("CREDIT", "#/components/schemas/Credit"); ComposedSchema sc = new ComposedSchema(); List oneOf = Arrays.asList( new Schema().$ref("#/components/schemas/Debit"), new Schema().$ref("#/components/schemas/Credit") ); sc.setOneOf(oneOf); sc.setDiscriminator(ds); md.schema(sc); openApi.getPaths().entrySet().stream() .flatMap(entry -> entry.getValue().readOperations().stream()) .forEach(op -> op.getRequestBody().getContent().addMediaType("application/json", md)); }; } |
Using the OpenApiCustomiser shoud be the silver bullet and the last solution to choose: Your requirement looks quite standard and doesn't require any customisations. As mentioned, you can simply add the |
It seems in the method of getSchemaFromAnnotation in AnnotationsUtils, it does not consider copying discriminatorProperty and discriminatorMapping.
The text was updated successfully, but these errors were encountered: