Skip to content

Wrong serializer used if array of string uses enum #1276

@fredmaggiowski

Description

@fredmaggiowski

Hello, we are facing a problem with an API that holds an array of strings which has specific allowed values defined by enum.

Such array is being transformed to a comma separated list rather than having a proper JSON serialization.

Portion of the JSON Schema we are using

  "requestBody": {
        "content": {
            "application/json": {
                "schema": {
                    "additionalProperties": false,
                    "properties": {
                        "contexts": {
                            "items": {
                                "enum": [
                                    "company",
                                    "project"
                                ],
                                "type": "string"
                            },
                            "type": "array"
                        },

This JSON schema is correctly interpreted by Swagger UI

immagine

However when serializing the payload we get this result:

{
    contexts: 'company, project',
    name: 'extension name'
}

I've reproduced this issue in a test I have in my project where I'm intercepting the request produced by the generated client:

Screenshot 2024-07-12 alle 17 08 03

After doing a bit of reverse engineering I've found this line that may be the culprint

immagine

As far as I understood, here the contexts field is being registered as an enum rather than an CollectionOfObjects and I think may be the cause of the serialization issue.

By updating the OAS definition not to use the enum there is a visible change to the above row: https://github.com/mia-platform/console-sdk/pull/186/files#diff-edaa8455836441c91748a0db0ddb0ae4d819148908dd0da2de5b92c60de36d5aR378

see mia-platform/console-sdk#186

- if(extensionsPutRequestBody.contexts)
-    writer.writeEnumValue<ExtensionsPutRequestBody_contexts>("contexts", ...extensionsPutRequestBody.contexts);
+writer.writeCollectionOfPrimitiveValues<string>("contexts", extensionsPutRequestBody.contexts);

Does this make sense, do you have any insights of something I may overlook?

Thanks

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done ✔️

Relationships

None yet

Development

No branches or pull requests

Issue actions