You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "dmvk (via GitHub)" <gi...@apache.org> on 2023/03/09 15:34:19 UTC

[GitHub] [flink] dmvk commented on a diff in pull request #22139: [FLINK-31383] Add support for documenting additionProperties of the R…

dmvk commented on code in PR #22139:
URL: https://github.com/apache/flink/pull/22139#discussion_r1131208707


##########
flink-docs/src/main/java/org/apache/flink/docs/rest/OpenApiSpecGenerator.java:
##########
@@ -452,7 +447,26 @@ private static Content createContentWithMediaType(String mediaType, Schema schem
     }
 
     private static Schema<?> getSchema(Type type) {
-        return modelConverterContext.resolve(new AnnotatedType(type).resolveAsRef(true));
+        final AnnotatedType annotatedType = new AnnotatedType(type).resolveAsRef(true);
+        final Schema<?> schema = modelConverterContext.resolve(annotatedType);
+        if (type instanceof Class<?>) {
+            final Class<?> clazz = (Class<?>) type;
+            ApiGeneratorUtils.findAdditionalFieldType(clazz)
+                    .map(OpenApiSpecGenerator::getSchema)
+                    .ifPresent(
+                            additionalPropertiesSchema -> {
+                                // We can not reuse the schema instance returned by the converter
+                                // above, because it's a different instance than the resolver has
+                                // defined, so we wouldn't see the changes later when populating
+                                // OpenAPI components.
+                                final Schema<?> definedModel =

Review Comment:
   Nope, the `#schema` returned by resolved is a wrapper that contains a reference to the `#definedModel` (which is a component)
   
   The valuable property here is that if more endpoints would be using the same class as a body, we only need to define the structure of the class; in this case, `#/components/schemas/AdditionalFieldsRequestBody` only needs to be defined once.
   
   Thanks for the question; it pushed me in the right direction to finally understand what's going on there. I'll adjust the comment to reflect the finding.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org