Skip to content
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

Response is different than in example #55

Open
JercSi opened this issue May 6, 2021 · 2 comments
Open

Response is different than in example #55

JercSi opened this issue May 6, 2021 · 2 comments

Comments

@JercSi
Copy link

JercSi commented May 6, 2021

I have an issue with using an example and actual result, that mock server returns. Values are not in the same order.

I am using lastest docker image with environment:

  • OPENAPI_MOCK_USE_EXAMPLES=if_present

Expected result:

{
  "0_0": "0",
  "1_1": "1",
  "2_2": "2",
  "3_3": "3",
  "4_4": "4",
  "5_5": "5",
  "6_6": "6",
  "7_7": "7",
  "8_8": "8",
  "9_9": "9",
  "10_10": "10",
  "11_11": "11",
  "12_12": "12"
}

Actual result - values 10_10, 11_11 and 12_12 are not in the expected position.

{
  "0_0": "0",
  "10_10": "10",
  "11_11": "11",
  "12_12": "12",
  "1_1": "1",
  "2_2": "2",
  "3_3": "3",
  "4_4": "4",
  "5_5": "5",
  "6_6": "6",
  "7_7": "7",
  "8_8": "8",
  "9_9": "9"
}

Openapi file:

{
    "openapi": "3.0.3",
    "info": {
        "title": "Bug report",
        "description": "Bug report",
        "version": "1.0.0"
    },
    "servers": [
        {
            "url": "http://localhost:20002/",
            "description": "Mockup server",
            "variables": {
                "port": {
                    "enum": [
                        "80"
                    ],
                    "default": "80"
                }
            }
        }
    ],
    "paths": {
        "/bug": {
            "get": {
                "description": "Bug report - example values mixed",
                "responses": {
                    "200": {
                        "description": "Example",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "title": "items",
                                    "example": {
                                        "0_0": "0",
                                        "1_1": "1",
                                        "2_2": "2",
                                        "3_3": "3",
                                        "4_4": "4",
                                        "5_5": "5",
                                        "6_6": "6",
                                        "7_7": "7",
                                        "8_8": "8",
                                        "9_9": "9",
                                        "10_10": "10",
                                        "11_11": "11",
                                        "12_12": "12"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
@strider2038
Copy link
Collaborator

Hello! This is because the map in Golang does not preserve the order of the attributes. Is it really needed? As I know JavaScript object does not guarantee the order of the attributes, see https://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order.

@JercSi
Copy link
Author

JercSi commented May 6, 2021

It's not really needed. I just came across this and I was expecting that response will be "copy & paste" from example without modifications.

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

No branches or pull requests

2 participants