Skip to content

Fix schema types seriallization #65

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

Merged
merged 12 commits into from
Jul 24, 2025

Conversation

AlexGuzmanAtAbsa
Copy link
Collaborator

@AlexGuzmanAtAbsa AlexGuzmanAtAbsa commented Jul 22, 2025

Strong data type serialization is lost because Swagger requires use of Schema[_] subtypes when modeling primitives, maps and arrays instead of the base Schema[_] class even if they have the same properties.

  • Fixes serialization of various data types in case classes including Map, List, String, Boolean which were incorrectly serialized to Any type
  • Update library versions

Tested using openapi Python generator. Verified types are now strongly typed and optional and mandatory fields are preseved as expected.

Test evidence

Example 1

case class StepFunctionDescriptor(
  arn: String,
  tags: Map[String, String] = Map.empty[String, String])

Current implementation:

            "StepFunctionDescriptor": {
                "properties": {
                    "arn": {},
                    "tags": {
                        "additionalProperties": {}
                    }
                },
                "required": [
                    "arn",
                    "tags"
                ]
            }

Notice above the absence of type for all properties resulting in the properties defaulting to Any in the generated OpenAPI JSON

After the fix:

           "StepFunctionDescriptor": {
                "type": "object",
                "properties": {
                    "arn": {
                        "type": "string"
                    },
                    "tags": {
                        "type": "object",
                        "additionalProperties": {
                            "type": "string"
                        }
                    }
                },
                "required": [
                    "arn",
                    "tags"
                ]
            },

Example 2

case class User(
  userName: String,
  firstName: Option[String],
  lastName: Option[String],
  mail: Option[String],
  groups: Seq[String])

Current implementation:

         "User": {
                "properties": {
                    "userName": {},
                    "firstName": {},
                    "lastName": {},
                    "mail": {},
                    "groups": {
                        "items": {}
                    }
                },
                "required": [
                    "groups",
                    "userName"
                ]
            }

After the fix:

           "User": {
                "type": "object",
                "properties": {
                    "userName": {
                        "type": "string"
                    },
                    "firstName": {
                        "type": "string"
                    },
                    "lastName": {
                        "type": "string"
                    },
                    "mail": {
                        "type": "string"
                    },
                    "groups": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    }
                },
                "required": [
                    "groups",
                    "userName"
                ]
            }

@AlexGuzmanAtAbsa AlexGuzmanAtAbsa marked this pull request as draft July 22, 2025 07:19
Copy link

github-actions bot commented Jul 22, 2025

JaCoCo code coverage report - springdoc-openapi-scala-1

Overall Project 97.99% -6.62% 🍏
Files changed 84.18% 🍏

File Coverage
OpenAPIModelRegistration.scala 97.94% -6.79% 🍏

Copy link

github-actions bot commented Jul 22, 2025

JaCoCo code coverage report - springdoc-openapi-scala-2

Overall Project 97.99% -6.62% 🍏
Files changed 84.18% 🍏

File Coverage
OpenAPIModelRegistration.scala 97.94% -6.79% 🍏

@AlexGuzmanAtAbsa AlexGuzmanAtAbsa marked this pull request as ready for review July 22, 2025 09:27
@jakipatryk
Copy link
Collaborator

I am not 100% sure what this PR tries to fix, could you please provide an example what is wrong currently?

@AlexGuzmanAtAbsa
Copy link
Collaborator Author

@jakipatryk Added some before vs after examples.

@kevinwallimann
Copy link
Contributor

I am not 100% sure what this PR tries to fix, could you please provide an example what is wrong currently?

We noticed that in our generated swagger docs (both api-docs endpoint and Swagger UI), certain types were missing from the properties, notably string or boolean. For some reason, integer types were present. Alex' examples are extracts from the api-docs endpoint

@AlexGuzmanAtAbsa AlexGuzmanAtAbsa merged commit ebdbbc2 into main Jul 24, 2025
2 checks passed
@AlexGuzmanAtAbsa AlexGuzmanAtAbsa deleted the feature/fix-opeani-serialization branch July 24, 2025 13:04
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

Successfully merging this pull request may close these issues.

3 participants