Skip to content

Serialisation of OpenAPI is not stable #728

@jmini

Description

@jmini

We have observed a strange behaviour with the Serialisation of an OpenAPI instance with Yaml.mapper().writeValueAsString(openAPI) produces different results:

--- a/src/main/resources/openapi.yaml
+++ b/src/main/resources/openapi.yaml
@@ -97,11 +97,11 @@ paths:
           type: array
           items:
             type: string
-            default: available
             enum:
             - available
             - pending
             - sold
+            default: available
       responses:
         200:
           description: successful operation
@@ -678,20 +678,20 @@ paths:
           type: array
           items:
             type: string
-            default: $
             enum:
             - '>'
             - $
+            default: $
       - name: enum_header_string
         in: header
         description: Header parameter enum test (string)
         schema:
           type: string
-          default: -efg
           enum:
           - _abc
           - -efg
           - (xyz)
+          default: -efg
       - name: enum_query_string_array
         in: query
         description: Query parameter enum test (string array)
@@ -701,20 +701,20 @@ paths:
           type: array
           items:
             type: string
-            default: $
             enum:
             - '>'
             - $
+            default: $
       - name: enum_query_string
         in: query
         description: Query parameter enum test (string)
         schema:
           type: string
-          default: -efg
           enum:
           - _abc
           - -efg
           - (xyz)
+          default: -efg
       - name: enum_query_integer
         in: query
         description: Query parameter enum test (double)
@@ -743,18 +743,18 @@ paths:
                   description: Form parameter enum test (string array)
                   items:
                     type: string
-                    default: $
                     enum:
                     - '>'
                     - $
+                    default: $
                 enum_form_string:
                   type: string
                   description: Form parameter enum test (string)
-                  default: -efg
                   enum:
                   - _abc
                   - -efg
                   - (xyz)
+                  default: -efg
       responses:
         400:
           description: Invalid request
@@ -1214,11 +1214,11 @@ components:
         name: Name
     EnumClass:
       type: string
-      default: -efg
       enum:
       - _abc
       - -efg
       - (xyz)
+      default: -efg
     List:
       type: object
       properties:

From a semantic point of view, the content is the same. But my expectation is to get the content always serialised the same way.

I did not understood what is producing the difference.
Maybe it depends from the JVM.

In my opinion io.swagger.v3.core.jackson.SchemaSerializer could and should be improved. It seems to me that the defaultSerializer is not working as expected.

I am open for suggestions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions