Skip to content

[Bug]: Client serialization does not preserve the API's expected JSON property names and enum representation #12764

Description

@j-steuer

Description

The OpenAPI specification defines the request body using camelCase property names and the lowercase enum value "available". The generated client produces a different representation.

Swagger Codegen Version

3.0.82

Language / Generator

  • csharp

OpenAPI/Swagger Spec

{
    "openapi": "3.0.0",
    "info": {
        "title": "Serializer Test API",
        "version": "0.0.0"
    },
    "tags": [
        {
            "name": "test",
            "description": "Serializer test operations"
        }
    ],
    "paths": {
        "/test": {
            "post": {
                "tags": [
                    "test"
                ],
                "operationId": "post_test_xcuctqa",
                "summary": "Test model serialization",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/TestModel"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "TestModel": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer",
                        "format": "int64"
                    },
                    "firstName": {
                        "type": "string"
                    },
                    "optionalValue": {
                        "type": "string"
                    },
                    "status": {
                        "type": "string",
                        "enum": [
                            "available",
                            "pending"
                        ]
                    },
                    "tags": {
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/Tag"
                        }
                    }
                },
                "additionalProperties": false
            },
            "Tag": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer",
                        "format": "int64"
                    },
                    "name": {
                        "type": "string"
                    }
                },
                "additionalProperties": false
            }
        }
    }
}

Command Line Used

I am using a script that uses the basic command

docker run --rm \
    --user "$(id -u):$(id -g)" \
    -v "$(pwd)":/local \
    -v "$PARENT_DIR":/output \
    swaggerapi/swagger-codegen-cli-v3:3.0.82 \
    generate \
    -i /local/spec/openapi.json \
    -l "$LANG" \
    -o "/output/$OUT_NAME"

and in this case uses 'csharp' for $LANG

Steps to Reproduce

  1. Generate a client using the provided specification
  2. Send a request using
var body = new TestModel
{
    Id = 1,
    FirstName = "test",
    Status = TestModel.StatusEnum.Available
};

await api.PostTestXcuctqaAsync(body);
  1. Observe the outgoing request body

Expected Behavior

The serialized request body should use the property names and enum values defined by the OpenAPI specification:

{
"id": 1,
"firstName": "test",
"status": "available"
}

Actual Behavior

The generated client serializes the model as:

{
"Status": "Available",
"Id": 1,
"FirstName": "test",
"OptionalValue": null,
"Tags": null
}

Related Issues / Repos

Environment

  • OS: Fedora 43

Additional Context

Checklist

  • I have searched the existing issues to make sure this is not a duplicate.
  • I have included a minimal and reproducible spec example.
  • I have explained how to reproduce the issue.
  • I have specified which generator/language is affected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions